Default delete crafty logs after 2 weeks

This commit is contained in:
amcmanu3 2023-02-26 16:38:27 -05:00
parent a62964f3e1
commit 6e35d4ae97
2 changed files with 32 additions and 2 deletions

View File

@ -441,6 +441,7 @@ class Helpers:
"reset_secrets_on_next_boot": False,
"monitored_mounts": mounts,
"dir_size_poll_freq_minutes": 5,
"crafty_logs_delete_after_days": 14,
}
def get_all_settings(self):

View File

@ -751,10 +751,39 @@ class TasksManager:
logger.debug("Could not clear out file from import directory")
def log_watcher(self):
self.controller.servers.check_for_old_logs()
self.check_for_old_logs()
self.scheduler.add_job(
self.controller.servers.check_for_old_logs,
self.check_for_old_logs,
"interval",
hours=6,
id="log-mgmt",
)
def check_for_old_logs(self):
# check for server logs first
self.controller.servers.check_for_old_logs()
# check for crafty logs now
logs_path = os.path.join(self.controller.project_root, "logs")
logs_delete_after = int(
self.helper.get_setting("crafty_logs_delete_after_days")
)
latest_log_files = [
"session.log",
"schedule.log",
"tornado-access.log",
"session.log",
"commander.log",
]
log_files = list(
filter(
lambda val: val not in latest_log_files,
os.listdir(logs_path),
)
)
for log_file in log_files:
log_file_path = os.path.join(logs_path, log_file)
if Helpers.check_file_exists(
log_file_path
) and Helpers.is_file_older_than_x_days(log_file_path, logs_delete_after):
os.remove(log_file_path)