summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorsuchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com>2023-08-12 00:02:30 +0200
committerGitHub <noreply@github.com>2023-08-11 23:02:30 +0100
commitdd130dbbd73244119c20c3b0f6224aa84671c807 (patch)
tree536359e68458ba5a19b7802d08df718700d9331d /plugin
parent9233495cac02dfd9a44b2358156ccab21de1bf2a (diff)
downloaddecky-loader-dd130dbbd73244119c20c3b0f6224aa84671c807.tar.gz
decky-loader-dd130dbbd73244119c20c3b0f6224aa84671c807.zip
Only keep up to 5 recent logs of runs of plugins (#525)
Diffstat (limited to 'plugin')
-rw-r--r--plugin/decky_plugin.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/plugin/decky_plugin.py b/plugin/decky_plugin.py
index 70cfe6ea..35b872a0 100644
--- a/plugin/decky_plugin.py
+++ b/plugin/decky_plugin.py
@@ -17,6 +17,7 @@ __version__ = '0.1.0'
import os
import subprocess
import logging
+import time
"""
Constants
@@ -117,7 +118,8 @@ Environment variable: `DECKY_PLUGIN_AUTHOR`.
e.g.: `John Doe`
"""
-DECKY_PLUGIN_LOG: str = os.path.join(DECKY_PLUGIN_LOG_DIR, "plugin.log")
+__cur_time = time.strftime("%Y-%m-%d %H.%M.%S")
+DECKY_PLUGIN_LOG: str = os.path.join(DECKY_PLUGIN_LOG_DIR, f"{__cur_time}.log")
"""
The path to the plugin's main logfile.
Environment variable: `DECKY_PLUGIN_LOG`.
@@ -192,6 +194,12 @@ def migrate_logs(*files_or_directories: str) -> dict[str, str]:
Logging
"""
+try:
+ for x in [entry.name for entry in sorted(os.scandir(DECKY_PLUGIN_LOG_DIR),key=lambda x: x.stat().st_mtime, reverse=True) if entry.name.endswith(".log")][4:]:
+ os.unlink(os.path.join(DECKY_PLUGIN_LOG_DIR, x))
+except Exception as e:
+ print(f"Failed to delete old logs: {str(e)}")
+
logging.basicConfig(filename=DECKY_PLUGIN_LOG,
format='[%(asctime)s][%(levelname)s]: %(message)s',
force=True)