From b1e82ed95ac66ef16626bb3638c92880660c0113 Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Sat, 21 Oct 2023 13:15:30 -0400 Subject: [PATCH] Cleanup old log format --- src/qz/App.java | 1 + src/qz/installer/Installer.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/qz/App.java b/src/qz/App.java index a5853b314..8b17dbe2b 100644 --- a/src/qz/App.java +++ b/src/qz/App.java @@ -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) diff --git a/src/qz/installer/Installer.java b/src/qz/installer/Installer.java index e6a9bacf9..2c644af41 100644 --- a/src/qz/installer/Installer.java +++ b/src/qz/installer/Installer.java @@ -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 dirs = new ArrayList<>(); ArrayList files = new ArrayList<>();