Skip to content

telemetry

Class info

Classes

Name Children Inherits
PrefixedLogger
mkdocs_mknodes.telemetry
A logger adapter to prefix log messages.

    🛈 DocStrings

    PrefixedLogger

    Bases: LoggerAdapter

    A logger adapter to prefix log messages.

    Source code in mkdocs_mknodes/telemetry.py
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    class PrefixedLogger(logging.LoggerAdapter):
        """A logger adapter to prefix log messages."""
    
        def __init__(self, prefix: str, logger: logging.Logger) -> None:
            """Initialize the logger adapter.
    
            Args:
                prefix: The string to insert in front of every message.
                logger: The logger instance.
            """
            super().__init__(logger, {})
            self.prefix = prefix
    
        def process(self, msg: str, kwargs: MutableMapping[str, Any]) -> tuple[str, Any]:
            """Process the message.
    
            Args:
                msg: The message:
                kwargs: Remaining arguments.
    
            Returns:
                The processed message.
            """
            return f"{self.prefix}: {msg}", kwargs
    

    __init__

    __init__(prefix: str, logger: Logger) -> None
    

    Initialize the logger adapter.

    Parameters:

    Name Type Description Default
    prefix str

    The string to insert in front of every message.

    required
    logger Logger

    The logger instance.

    required
    Source code in mkdocs_mknodes/telemetry.py
    52
    53
    54
    55
    56
    57
    58
    59
    60
    def __init__(self, prefix: str, logger: logging.Logger) -> None:
        """Initialize the logger adapter.
    
        Args:
            prefix: The string to insert in front of every message.
            logger: The logger instance.
        """
        super().__init__(logger, {})
        self.prefix = prefix
    

    process

    process(msg: str, kwargs: MutableMapping[str, Any]) -> tuple[str, Any]
    

    Process the message.

    Parameters:

    Name Type Description Default
    msg str

    The message:

    required
    kwargs MutableMapping[str, Any]

    Remaining arguments.

    required

    Returns:

    Type Description
    tuple[str, Any]

    The processed message.

    Source code in mkdocs_mknodes/telemetry.py
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    def process(self, msg: str, kwargs: MutableMapping[str, Any]) -> tuple[str, Any]:
        """Process the message.
    
        Args:
            msg: The message:
            kwargs: Remaining arguments.
    
        Returns:
            The processed message.
        """
        return f"{self.prefix}: {msg}", kwargs
    

    get_plugin_logger

    get_plugin_logger(name: str) -> PrefixedLogger
    

    Return a logger for plugins.

    Parameters:

    Name Type Description Default
    name str

    The name to use with logging.getLogger.

    required

    Returns:

    Type Description
    PrefixedLogger

    A logger configured to work well in MkDocs, prefixing each message with the plugin package name.

    Example
    from mkdocs.plugins import get_plugin_logger
    
    log = get_plugin_logger(__name__)
    log.info("My plugin message")
    
    Source code in mkdocs_mknodes/telemetry.py
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    def get_plugin_logger(name: str) -> PrefixedLogger:
        """Return a logger for plugins.
    
        Args:
            name: The name to use with `logging.getLogger`.
    
        Returns:
            A logger configured to work well in MkDocs,
                prefixing each message with the plugin package name.
    
        Example:
            ```python
            from mkdocs.plugins import get_plugin_logger
    
            log = get_plugin_logger(__name__)
            log.info("My plugin message")
            ```
        """
        logger = logging.getLogger(f"mkdocs.plugins.{name}")
        logger.addHandler(logfire.LogfireLoggingHandler())
        return PrefixedLogger(name.split(".", 1)[0], logger)