diff --git a/flares.py b/flares.py index d308f25..9a365fa 100644 --- a/flares.py +++ b/flares.py @@ -310,21 +310,39 @@ script_dir = os.path.dirname(os.path.abspath(__file__)) os.chdir(script_dir) -# Configure logging to file with timestamps and realtime flush +# Configure logging with rotation to prevent indefinite growth +# Issue #114: Log file should not grow indefinitely - now rotates at 10MB, keeps 5 backups +import logging.handlers + if PLATFORM_NAME == 'darwin': log_path = os.path.abspath(os.path.join(os.path.dirname(sys.executable), "../../../fnirs_analysis.log")) else: log_path = os.path.join(get_app_dir(), "fnirs_analysis.log") -logging.basicConfig( - filename=log_path, - level=logging.INFO, - format='%(asctime)s - %(processName)s - %(levelname)s - %(message)s', - datefmt='%Y-%m-%d %H:%M:%S', - filemode='a' +# Create logger +logger = logging.getLogger() +logger.setLevel(logging.INFO) + +# Clear any existing handlers +logger.handlers.clear() + +# Create rotating file handler (max 10MB per file, keep 5 backups = ~50MB max total) +rotating_handler = logging.handlers.RotatingFileHandler( + log_path, + maxBytes=10*1024*1024, # 10 MB + backupCount=5, # Keep 5 backup files + encoding='utf-8' ) -logger = logging.getLogger() +# Set formatter +formatter = logging.Formatter( + '%(asctime)s - %(processName)s - %(levelname)s - %(message)s', + datefmt='%Y-%m-%d %H:%M:%S' +) +rotating_handler.setFormatter(formatter) + +# Add handler to logger +logger.addHandler(rotating_handler) def set_config_me(config: dict[str, Any]) -> None: