Further tweaks
This commit is contained in:
+25
-3
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user