Fix #114: Implement log rotation for fnirs_analysis.log
Test Suite / test (push) Canceled after 0s

Add RotatingFileHandler to prevent indefinite log growth.
- Rotates at 10MB per file
- Keeps 5 backup files (~50MB max total)
- Addresses issue #114 (Kind/Enhancement, Priority/Medium)
This commit is contained in:
Hermes committed 2026-11-07 17:19:46 -07:00
1 parent 5d7e497a10
commit 895695148b
1 file changed
+26 -8
+26 -8
View File
@@ -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: