Skip to content

Size based rolling support for file sink #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,31 @@

public class PathManager {

private long seriesTimestamp;
private File baseDirectory;
private AtomicInteger fileIndex;

private String fileName;

private File currentFile;

public PathManager() {
seriesTimestamp = System.currentTimeMillis();
fileIndex = new AtomicInteger();
public PathManager(String fileName, int maxRolledCount) {
this.fileName = fileName;
fileIndex = new AtomicInteger(maxRolledCount);
}

public File nextFile() {
currentFile = new File(baseDirectory, seriesTimestamp + "-"
+ fileIndex.incrementAndGet());

return currentFile;
public File nextRotatedFile() {
return new File(baseDirectory, fileName + "-" + fileIndex.incrementAndGet());
}

public File getCurrentFile() {
if (currentFile == null) {
return nextFile();
currentFile = new File(baseDirectory, fileName);
}

return currentFile;
}

public void rotate() {
currentFile.renameTo(nextRotatedFile());
currentFile = null;
}

Expand All @@ -62,8 +60,8 @@ public void setBaseDirectory(File baseDirectory) {
this.baseDirectory = baseDirectory;
}

public long getSeriesTimestamp() {
return seriesTimestamp;
public String getFileName() {
return fileName;
}

public AtomicInteger getFileIndex() {
Expand Down
Loading