feat: structured DEBUG/INFO logging via loguru
- common/logging.py: improve format to timestamp|LEVEL|module:func:line - message - core/ layer: DEBUG log every subprocess invocation (cmd, rc, byte counts), JSON load/dump events, parsed application_id. ERROR log on failures. - tools/ layer: DEBUG log every public tool entry with key parameters, INFO log on business outcomes (saved/submitted/killed/...). - New tests/unit/test_logging.py: capture loguru output via in-memory sink and assert DEBUG + INFO messages are emitted for representative flows.
This commit is contained in:
+21
-2
@@ -1,10 +1,29 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
@Time :2026/6/24
|
||||
@Author :tao.chen
|
||||
@Author :tao.chen
|
||||
|
||||
Process-wide loguru configuration. Import `logger` from here in every
|
||||
module instead of instantiating new loggers.
|
||||
|
||||
Levels used in this project:
|
||||
DEBUG - entry/exit of public tools, subprocess commands, file I/O paths
|
||||
INFO - business events (job submitted, status changed, connection saved)
|
||||
WARNING - recoverable problems (transient YARN issues, retry-able)
|
||||
ERROR - raised exceptions (caller will see the traceback)
|
||||
"""
|
||||
import sys
|
||||
|
||||
from loguru import logger
|
||||
|
||||
logger.remove()
|
||||
logger.add(sys.stderr, level="DEBUG")
|
||||
logger.add(
|
||||
sys.stderr,
|
||||
level="DEBUG",
|
||||
format=(
|
||||
"<green>{time:HH:mm:ss.SSS}</green> | "
|
||||
"<level>{level: <7}</level> | "
|
||||
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
|
||||
"<level>{message}</level>"
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user