Path: /utilities/util_logger.py
Provides centralized logging for Talon by configuring console and rotating file handlers, setting formatting, and capturing uncaught exceptions.
Initialize a consistent logger across Talon components to capture debug, info, warning, and error messages.
Automatically log uncaught exceptions from the main thread and worker threads for easier diagnosis.
logging
logging.handlers
os
sys
threading
warnings
Parameter | Type | Description | Default |
---|---|---|---|
name | string | Name of the logger to configure; if None, the root logger is used. | None |
log_file | string | Path to the log file; if None, defaults to <base_path>/talon.log. | None |
level | int | Logging level threshold; can also be set via TALON_LOG_LEVEL environment variable. | logging.DEBUG |
max_bytes | int | Maximum size in bytes for each rotated log file. | 10485760 |
backup_count | int | Number of rotated log files to retain. | 5 |
python -c "import logging; from utilities.util_logger import setup_logger; \
logger = setup_logger(name='myapp', log_file='myapp.log', level=logging.INFO); \
logger.info('Application started')"
Determines the base path (application directory or frozen executable path), creates console and rotating file handlers with the specified level and formatting, attaches them to the logger, and installs exception hooks via sys.excepthook and threading.excepthook to log uncaught exceptions.
Initialization failures (e.g., invalid file paths) propagate exceptions. Uncaught exceptions in any thread are logged at the ERROR level with full traceback.
Log files may contain sensitive information; ensure appropriate file permissions. Avoid logging secrets or personal data at high verbosity levels.
Uses DEBUG, INFO, WARNING, and ERROR levels. Example entry:
2025-06-21 14:32:10 [DEBUG] root util_logger.setup_logger:45 [pid:1234 tid:140735864540544]: Logger initialized (level=DEBUG, file=/path/to/talon.log, maxBytes=10485760, backups=5)
Run unit tests to verify that log files are created at the correct location, rotated after exceeding max_bytes, and that uncaught exceptions are captured. Example:
pytest tests/util/test_util_logger.py
Author: Raven Development Team