Files
iklim-sandbox/common/logging_config.py
T
2026-09-09 16:21:13 +03:00

38 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Console and rotating debug-file logging configuration."""
from __future__ import annotations
import logging
from logging.handlers import RotatingFileHandler
from pathlib import Path
def configure_logging(debug_log_file: Path) -> Path:
debug_log_file = debug_log_file.resolve()
debug_log_file.parent.mkdir(parents=True, exist_ok=True)
root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
root_logger.handlers.clear()
formatter = logging.Formatter(
"%(asctime)s | %(levelname)s | %(name)s | %(message)s"
)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(formatter)
file_handler = RotatingFileHandler(
debug_log_file,
maxBytes=5 * 1024 * 1024,
backupCount=3,
encoding="utf-8",
)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
root_logger.addHandler(console_handler)
root_logger.addHandler(file_handler)
logging.getLogger(__name__).info("Debug log dosyası: %s", debug_log_file)
return debug_log_file