Coverage for src/mkdocs_coverage/loggers.py: 93.33%
15 statements
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-11 20:38 +0200
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-11 20:38 +0200
1"""Logging functions."""
3from __future__ import annotations
5try:
6 from mkdocs.plugin import get_plugin_logger
7except ImportError:
8 # TODO: remove once support for MkDocs <1.5 is dropped
9 import logging
10 from typing import Any, MutableMapping
12 class PrefixedLogger(logging.LoggerAdapter): # noqa: D101
13 def __init__(self, prefix: str, logger: logging.Logger) -> None: # noqa: D107
14 super().__init__(logger, {})
15 self.prefix = prefix
17 def process(self, msg: str, kwargs: MutableMapping[str, Any]) -> tuple[str, Any]: # noqa: D102
18 return f"{self.prefix}: {msg}", kwargs
20 def get_plugin_logger(name: str) -> PrefixedLogger: # noqa: D103
21 logger = logging.getLogger(f"mkdocs.plugins.{name}")
22 return PrefixedLogger(name.split(".", 1)[0], logger)