Skip to content

Commit

Permalink
Cleanup old log format
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Oct 21, 2023
1 parent cfaab7e commit b1e82ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/qz/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private static void setupFileLogging() {

int logSize = PrefsSearch.getInt(ArgValue.LOG_SIZE);
int logRotate = PrefsSearch.getInt(ArgValue.LOG_ROTATE);
Installer.getInstance().removeLegacyLogs(logRotate);
RollingFileAppender fileAppender = RollingFileAppender.newBuilder()
.setName("log-file")
.withAppend(true)
Expand Down
18 changes: 18 additions & 0 deletions src/qz/installer/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ public Installer removeLibs() {
return this;
}

public Installer removeLegacyLogs(int rolloverCount) {
// Cleanup old < 2.2.3 log file format
Path logLocation = USER_DIR;
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();
}
}

return this;
}

public Installer removeLegacyFiles() {
ArrayList<String> dirs = new ArrayList<>();
ArrayList<String> files = new ArrayList<>();
Expand Down

0 comments on commit b1e82ed

Please sign in to comment.