Skip to content

Commit

Permalink
Switch from "max" to "min" rollover, address comments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Oct 22, 2023
1 parent af9d61a commit 9c1e82f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/qz/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ private static void setupFileLogging() {
.setFilter(ThresholdFilter.createFilter(Level.DEBUG, Filter.Result.ACCEPT, Filter.Result.DENY))
.withFileName(FileUtilities.USER_DIR + File.separator + Constants.LOG_FILE + ".log")
.withFilePattern(FileUtilities.USER_DIR + File.separator + Constants.LOG_FILE + ".%i.log")
.withStrategy(DefaultRolloverStrategy.newBuilder().withMax(String.valueOf(logRotate)).build())
.withStrategy(DefaultRolloverStrategy.newBuilder()
.withMax(String.valueOf(logRotate))
.withFileIndex("min")
.build())
.withPolicy(SizeBasedTriggeringPolicy.createPolicy(String.valueOf(logSize)))
.withImmediateFlush(true)
.build();
Expand Down
21 changes: 14 additions & 7 deletions src/qz/installer/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,24 @@ public Installer removeLibs() {
}

public Installer removeLegacyLogs(int rolloverCount) {
// Cleanup old < 2.2.3 log file format
// Convert old < 2.2.3 log file format
Path logLocation = USER_DIR;
int nextFile = 0;
for(int i = 1; i <= rolloverCount; i++) {
// Old: debug.log.1
File newFile = logLocation.resolve("debug." + i + ".log").toFile();
// New: debug.1.log
File oldFile = logLocation.resolve("debug.log." + i).toFile();
// Only delete old if an adjacent new copy exists
if(oldFile.exists() && newFile.exists()) {
log.info("Cleaning up old log file {}", oldFile);
oldFile.delete();
if(oldFile.exists()) {
// Rename to new format
inner:
while(true) {
// New: debug.1.log
File newFile = logLocation.resolve("debug." + ++nextFile + ".log").toFile();
if (!newFile.exists()) {
oldFile.renameTo(newFile);
log.info("Migrated log file {} to new location {}", oldFile, newFile);
break inner;
}
}
}
}

Expand Down

0 comments on commit 9c1e82f

Please sign in to comment.