Fix #114: Implement log rotation for fnirs_analysis.log
Test Suite / test (push) Canceled after 0s
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:
1 parent
5d7e497a10
commit
895695148b
1 file changed
+26
-8
@@ -310,21 +310,39 @@ script_dir = os.path.dirname(os.path.abspath(__file__))
|
|||||||
os.chdir(script_dir)
|
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':
|
if PLATFORM_NAME == 'darwin':
|
||||||
log_path = os.path.abspath(os.path.join(os.path.dirname(sys.executable), "../../../fnirs_analysis.log"))
|
log_path = os.path.abspath(os.path.join(os.path.dirname(sys.executable), "../../../fnirs_analysis.log"))
|
||||||
else:
|
else:
|
||||||
log_path = os.path.join(get_app_dir(), "fnirs_analysis.log")
|
log_path = os.path.join(get_app_dir(), "fnirs_analysis.log")
|
||||||
|
|
||||||
logging.basicConfig(
|
# Create logger
|
||||||
filename=log_path,
|
logger = logging.getLogger()
|
||||||
level=logging.INFO,
|
logger.setLevel(logging.INFO)
|
||||||
format='%(asctime)s - %(processName)s - %(levelname)s - %(message)s',
|
|
||||||
datefmt='%Y-%m-%d %H:%M:%S',
|
# Clear any existing handlers
|
||||||
filemode='a'
|
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:
|
def set_config_me(config: dict[str, Any]) -> None:
|
||||||
|
|||||||
Reference in new issue
Block a user