Files
bedit/src/bedit_gui/services/application_logging.py
T
2026-07-26 14:46:18 +02:00

33 lines
962 B
Python

from __future__ import annotations
import logging
LOGGER_NAMESPACE = "bedit"
_application_logger = logging.getLogger(LOGGER_NAMESPACE)
_application_logger.propagate = False
_application_logger.addHandler(logging.NullHandler())
def get_logger(name: str) -> logging.Logger:
"""Return a logger routed to the BEdit application log."""
return logging.getLogger(f"{LOGGER_NAMESPACE}.{name}")
def configure_logging(
handler: logging.Handler,
level: int | str = logging.INFO,
) -> None:
"""Replace the application output handler and set its log level."""
for existing in list(_application_logger.handlers):
_application_logger.removeHandler(existing)
_application_logger.addHandler(handler)
set_log_level(level)
def set_log_level(level: int | str) -> None:
"""Set the minimum severity shown by all BEdit loggers."""
if isinstance(level, str):
level = level.upper()
_application_logger.setLevel(level)