Further tweaks

This commit is contained in:
ponzischeme89
2026-04-18 07:51:16 +12:00
parent 5ce13d0ba0
commit 1368810689
8 changed files with 58 additions and 113 deletions
+25 -3
View File
@@ -1,13 +1,35 @@
import logging
from pathlib import Path
from typing import Optional
DEFAULT_LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
DEFAULT_LOG_PATH = Path(__file__).resolve().parent.parent / "sublogue.log"
def configure_logging(level: int = logging.INFO, fmt: str = DEFAULT_LOG_FORMAT) -> None:
"""Configure application logging."""
logging.basicConfig(level=level, format=fmt)
def configure_logging(
level: int = logging.INFO,
fmt: str = DEFAULT_LOG_FORMAT,
log_path: Path = DEFAULT_LOG_PATH,
) -> None:
"""Configure console and root-level file logging for the application."""
root_logger = logging.getLogger()
if getattr(root_logger, "_sublogue_logging_configured", False):
return
formatter = logging.Formatter(fmt)
handlers = [
logging.StreamHandler(),
logging.FileHandler(log_path, encoding="utf-8"),
]
for handler in handlers:
handler.setFormatter(formatter)
root_logger.addHandler(handler)
root_logger.setLevel(level)
root_logger._sublogue_logging_configured = True
def get_logger(name: Optional[str] = None) -> logging.Logger: