marketflows.logging_utils
Logging helpers.
This module configures the root logger so application code can simply call
logging.getLogger(__name__) and emit messages.
Behavior:
A file handler is attached at the requested level (default:
INFO) and writes to an OS-appropriate directory (XDG_STATE_HOMEon Linux/WSL orLOCALAPPDATAon Windows).A stderr handler is attached at
WARNINGand above.Python warnings are routed through logging (via
logging.captureWarnings).
In tutorial mode (is_tutorial=True), log timestamps are made deterministic so
test outputs and tutorial logs are reproducible.
Functions
|
Configure root logging for the application. |
- marketflows.logging_utils.configure_logging(*, level='INFO', node='', is_tutorial=False)
Configure root logging for the application.
This attaches two handlers to the root logger:
A file handler at
levelwriting to<state-dir>/marketflows/logs/<node>.log. - On Linux/WSL:$XDG_STATE_HOME(fallback:~/.local/state) - On Windows:%LOCALAPPDATA%(fallback:~/AppData/Local)A stderr handler at
WARNINGand above.
Calling this function multiple times is safe: existing root handlers are removed and closed before new handlers are installed.
- Parameters:
level (str) – Logging level name (e.g.,
"DEBUG","INFO").node (str) – Logical node name used for the log filename.
is_tutorial (bool) – If True, use deterministic timestamps and overwrite the log file each run.
- Raises:
ValueError – If
levelis not a valid logging level name.- Return type:
None