mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-03-30 23:03:03 -07:00
@@ -35,26 +35,34 @@ def main():
|
|||||||
MAINT_LOG_LENGTH = int(get_setting_value('MAINT_LOG_LENGTH'))
|
MAINT_LOG_LENGTH = int(get_setting_value('MAINT_LOG_LENGTH'))
|
||||||
MAINT_NOTI_LENGTH = int(get_setting_value('MAINT_NOTI_LENGTH'))
|
MAINT_NOTI_LENGTH = int(get_setting_value('MAINT_NOTI_LENGTH'))
|
||||||
|
|
||||||
|
logFiles = ["app.log", "nginx-error.log", "stdout.log"]
|
||||||
|
|
||||||
# Check if set
|
# Check if set
|
||||||
if MAINT_LOG_LENGTH != 0:
|
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
|
logFile = logPath + "/" + fileEntry
|
||||||
lines_to_keep = deque(maxlen=MAINT_LOG_LENGTH)
|
|
||||||
|
|
||||||
with open(logFile, 'r') as file:
|
mylog('verbose', [f'[{pluginName}] {fileEntry} size BEFORE: {os.path.getsize(logFile)}'])
|
||||||
# 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:
|
# Using a deque to efficiently keep the last N lines
|
||||||
# Write the last N lines back to the file
|
lines_to_keep = deque(maxlen=MAINT_LOG_LENGTH)
|
||||||
file.writelines(lines_to_keep)
|
|
||||||
|
|
||||||
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
|
# Check if set
|
||||||
if MAINT_NOTI_LENGTH != 0:
|
if MAINT_NOTI_LENGTH != 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user