From 892e89bdfd52445c8ee476c83527eeda076ac7c7 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sat, 1 Feb 2025 17:22:50 +0100 Subject: [PATCH] adds rotation and overwriting logging I underestimated the amount of logs generated. This should keep it within limits most of the time. Might still be a lot of logs, but at least there's an upper limit now. --- bin/vcmp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/vcmp b/bin/vcmp index 746c47c..972b827 100755 --- a/bin/vcmp +++ b/bin/vcmp @@ -7,6 +7,7 @@ import sys import argparse import tempfile import logging +from logging.handlers import RotatingFileHandler import time import psutil from tqdm import tqdm @@ -79,10 +80,14 @@ def setup_logging(verbose: bool) -> None: console_handler.setLevel(log_level) console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')) - # Create file handler - file_handler = logging.FileHandler(log_file) + # Create rotating file handler + file_handler = RotatingFileHandler( + log_file, + backupCount=100 + ) file_handler.setLevel(logging.DEBUG) # Always log everything to file file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')) + file_handler.doRollover() # Set up root logger root_logger = logging.getLogger() @@ -176,7 +181,7 @@ def run(filepath: pathlib.Path, cmd: list[str], temp_path: pathlib.Path, file_in ffmpeg_log_path = pathlib.Path(xdg_state_home) / 'vcmp' / 'ffmpeg.log' ffmpeg_log_path.parent.mkdir(parents=True, exist_ok=True) - with open(ffmpeg_log_path, 'a') as log_file: + with open(ffmpeg_log_path, 'w') as log_file: process = subprocess.Popen( cmd, stdout=subprocess.PIPE,