Logging
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user