mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Default delete crafty logs after 2 weeks
This commit is contained in:
parent
a62964f3e1
commit
6e35d4ae97
@ -441,6 +441,7 @@ class Helpers:
|
|||||||
"reset_secrets_on_next_boot": False,
|
"reset_secrets_on_next_boot": False,
|
||||||
"monitored_mounts": mounts,
|
"monitored_mounts": mounts,
|
||||||
"dir_size_poll_freq_minutes": 5,
|
"dir_size_poll_freq_minutes": 5,
|
||||||
|
"crafty_logs_delete_after_days": 14,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_all_settings(self):
|
def get_all_settings(self):
|
||||||
|
@ -751,10 +751,39 @@ class TasksManager:
|
|||||||
logger.debug("Could not clear out file from import directory")
|
logger.debug("Could not clear out file from import directory")
|
||||||
|
|
||||||
def log_watcher(self):
|
def log_watcher(self):
|
||||||
self.controller.servers.check_for_old_logs()
|
self.check_for_old_logs()
|
||||||
self.scheduler.add_job(
|
self.scheduler.add_job(
|
||||||
self.controller.servers.check_for_old_logs,
|
self.check_for_old_logs,
|
||||||
"interval",
|
"interval",
|
||||||
hours=6,
|
hours=6,
|
||||||
id="log-mgmt",
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user