Files
uipath-explainator/src/uipath_explainator/logging_utils.py
xiaomai 0bdebd5368 feat(logging): add configurable logging with file output support
Introduce --log-level and --log-file CLI arguments.
Add execution time tracking and detailed logs across all modules.
2026-04-02 10:40:39 +08:00

29 lines
847 B
Python

from __future__ import annotations
from pathlib import Path
import logging
LOG_FORMAT = "%(asctime)s %(levelname)s [%(name)s] %(message)s"
def configure_logging(level_name: str = "INFO", log_file: Path | None = None) -> None:
level = getattr(logging, level_name.upper(), logging.INFO)
formatter = logging.Formatter(LOG_FORMAT)
handlers: list[logging.Handler] = [logging.StreamHandler()]
if log_file is not None:
log_file.parent.mkdir(parents=True, exist_ok=True)
handlers.append(logging.FileHandler(log_file, encoding="utf-8"))
root_logger = logging.getLogger()
root_logger.handlers.clear()
root_logger.setLevel(level)
for handler in handlers:
handler.setLevel(level)
handler.setFormatter(formatter)
root_logger.addHandler(handler)
logging.captureWarnings(True)