Coverage for src/mkdocs_spellcheck/loggers.py: 0.00%

12 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-05 19:28 +0200

1"""Logging functions.""" 

2 

3from __future__ import annotations 

4 

5import logging 

6from typing import Any, MutableMapping 

7 

8 

9# TODO: remove once support for MkDocs <1.5 is dropped (use built-in) 

10class PrefixedLogger(logging.LoggerAdapter): # noqa: D101 

11 def __init__(self, prefix: str, logger: logging.Logger) -> None: # noqa: D107 

12 super().__init__(logger, {}) 

13 self.prefix = prefix 

14 

15 def process(self, msg: str, kwargs: MutableMapping[str, Any]) -> tuple[str, Any]: # noqa: D102 

16 return f"{self.prefix}: {msg}", kwargs 

17 

18 

19def get_plugin_logger(name: str) -> PrefixedLogger: # noqa: D103 

20 logger = logging.getLogger(f"mkdocs.plugins.{name}") 

21 return PrefixedLogger(name.split(".", 1)[0], logger)