This commit is contained in:
Joppe Blondel
2026-07-26 14:46:18 +02:00
parent 810f993830
commit 3bd6cfb81d
8 changed files with 259 additions and 3 deletions
@@ -0,0 +1,32 @@
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)