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,