From 54e8a2fe000aa62b0cdbe98781b8f8b8b14b36e6 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sat, 3 Jan 2026 08:27:45 +1100 Subject: [PATCH] PLG: MAINT logs cleanup Signed-off-by: jokob-sk --- front/plugins/maintenance/maintenance.py | 32 +++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/front/plugins/maintenance/maintenance.py b/front/plugins/maintenance/maintenance.py index c12d0607..85caf0b1 100755 --- a/front/plugins/maintenance/maintenance.py +++ b/front/plugins/maintenance/maintenance.py @@ -35,26 +35,34 @@ def main(): MAINT_LOG_LENGTH = int(get_setting_value('MAINT_LOG_LENGTH')) MAINT_NOTI_LENGTH = int(get_setting_value('MAINT_NOTI_LENGTH')) + logFiles = ["app.log", "nginx-error.log", "stdout.log"] + # Check if set if MAINT_LOG_LENGTH != 0: - mylog('verbose', [f'[{pluginName}] Cleaning file']) + for fileEntry in logFiles: - logFile = logPath + "/app.log" + mylog('verbose', [f'[{pluginName}] Cleaning file']) - # Using a deque to efficiently keep the last N lines - lines_to_keep = deque(maxlen=MAINT_LOG_LENGTH) + logFile = logPath + "/" + fileEntry - with open(logFile, 'r') as file: - # Read lines from the file and store the last N lines - for line in file: - lines_to_keep.append(line) + mylog('verbose', [f'[{pluginName}] {fileEntry} size BEFORE: {os.path.getsize(logFile)}']) - with open(logFile, 'w') as file: - # Write the last N lines back to the file - file.writelines(lines_to_keep) + # Using a deque to efficiently keep the last N lines + lines_to_keep = deque(maxlen=MAINT_LOG_LENGTH) - mylog('verbose', [f'[{pluginName}] Cleanup finished']) + with open(logFile, 'r') as file: + # Read lines from the file and store the last N lines + for line in file: + lines_to_keep.append(line) + + with open(logFile, 'w') as file: + # Write the last N lines back to the file + file.writelines(lines_to_keep) + + mylog('verbose', [f'[{pluginName}] {fileEntry} size AFTER: {os.path.getsize(logFile)}']) + + mylog('verbose', [f'[{pluginName}] Cleanup of {fileEntry} finished']) # Check if set if MAINT_NOTI_LENGTH != 0: