diff options
| -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) |
