1
0

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.
This commit is contained in:
2025-02-01 17:22:50 +01:00
parent c06eeda4f2
commit 892e89bdfd
+8 -3
View File
@@ -7,6 +7,7 @@ import sys
import argparse import argparse
import tempfile import tempfile
import logging import logging
from logging.handlers import RotatingFileHandler
import time import time
import psutil import psutil
from tqdm import tqdm from tqdm import tqdm
@@ -79,10 +80,14 @@ def setup_logging(verbose: bool) -> None:
console_handler.setLevel(log_level) console_handler.setLevel(log_level)
console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')) console_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
# Create file handler # Create rotating file handler
file_handler = logging.FileHandler(log_file) file_handler = RotatingFileHandler(
log_file,
backupCount=100
)
file_handler.setLevel(logging.DEBUG) # Always log everything to file file_handler.setLevel(logging.DEBUG) # Always log everything to file
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')) file_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
file_handler.doRollover()
# Set up root logger # Set up root logger
root_logger = logging.getLogger() 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 = pathlib.Path(xdg_state_home) / 'vcmp' / 'ffmpeg.log'
ffmpeg_log_path.parent.mkdir(parents=True, exist_ok=True) 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( process = subprocess.Popen(
cmd, cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,