diff options
| author | Pinapelz <yukais@pinapelz.com> | 2024-10-04 11:57:29 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2024-10-04 11:57:46 -0700 |
| commit | 274e2cb39841b71c1f1cc9e94b94c75f0ebed539 (patch) | |
| tree | a84afe0a8da5beeb2d20f35d446ff425130f0754 | |
| parent | a695e797d72ab3467b4bbd64eb5c9dbe6fea0111 (diff) | |
add logic to cut log file by half if exceeding 1000kb in 1 run
- should not ever happen but this is a failsafe
| -rw-r--r-- | logger.py | 13 | ||||
| -rw-r--r-- | nijitrack.py | 1 |
2 files changed, 12 insertions, 2 deletions
@@ -1,6 +1,7 @@ import time from datetime import datetime import pytz +import os def _get_datetime_string(): utc_now = datetime.now(pytz.timezone('UTC')) @@ -30,4 +31,14 @@ class Logger: def log(self, message: str): with open(self.path, "a") as file: - file.write(f"[{_get_datetime_string()}] {message}\n")
\ No newline at end of file + self.check_log_size() + file.write(f"[{_get_datetime_string()}] {message}\n") + + def check_log_size(self): + if os.path.getsize(self.path) > self.max_size_bytes: + with open(self.path, "r") as file: + lines = file.readlines() + with open(self.path, "w") as file: + file.writelines(lines[int(len(lines) / 2):]) + file.write("Removed half of the log file due to size\n") + diff --git a/nijitrack.py b/nijitrack.py index d40bc0b..13e5ef9 100644 --- a/nijitrack.py +++ b/nijitrack.py @@ -159,7 +159,6 @@ if __name__ == "__main__": parser.add_argument('--mode', choices=['yt', 'holodex'], help='Specify the data source to use (yt or holodex)') parser.add_argument('--b2', action='store_true', help="Upload graph html to Backblaze B2") parser.add_argument('--ff', action='store_true', help="Force a full refresh of all data (override daily refresh)") - parser.add_argument('--log', action='store_true', help="Log the output to a file") args = parser.parse_args() server = create_database_connection() initialize_database(server) |
