Skip to content

Loggers¤

Main API¤

logger module-attribute ¤

logger: Logger = _get()

Our global logger, used throughout the library.

Griffe's output and error messages are logging messages.

Griffe provides the patch_loggers function so dependent libraries can patch Griffe loggers as they see fit.

For example, to fit in the MkDocs logging configuration and prefix each log message with the module name:

import logging
from griffe import patch_loggers


class LoggerAdapter(logging.LoggerAdapter):
    def __init__(self, prefix, logger):
        super().__init__(logger, {})
        self.prefix = prefix

    def process(self, msg, kwargs):
        return f"{self.prefix}: {msg}", kwargs


def get_logger(name):
    logger = logging.getLogger(f"mkdocs.plugins.{name}")
    return LoggerAdapter(name, logger)


patch_loggers(get_logger)

get_logger ¤

get_logger(name: str = 'griffe') -> Logger

Create and return a new logger instance.

Parameters:

  • name ¤

    (str, default: 'griffe' ) –

    The logger name.

Returns:

Logger ¤

Logger(name: str)

Methods:

  • disable

    Temporarily disable logging.

disable ¤

disable() -> Iterator[None]

Temporarily disable logging.

LogLevel ¤


              flowchart TD
              griffe.LogLevel[LogLevel]

              

              click griffe.LogLevel href "" "griffe.LogLevel"
            

Enumeration of available log levels.

Attributes:

critical class-attribute instance-attribute ¤

critical: str = 'critical'

The CRITICAL log level.

debug class-attribute instance-attribute ¤

debug: str = 'debug'

The DEBUG log level.

error class-attribute instance-attribute ¤

error: str = 'error'

The ERROR log level.

info class-attribute instance-attribute ¤

info: str = 'info'

The INFO log level.

success class-attribute instance-attribute ¤

success: str = 'success'

The SUCCESS log level.

trace class-attribute instance-attribute ¤

trace: str = 'trace'

The TRACE log level.

warning class-attribute instance-attribute ¤

warning: str = 'warning'

The WARNING log level.

DEFAULT_LOG_LEVEL module-attribute ¤

DEFAULT_LOG_LEVEL = os.getenv(
    "GRIFFE_LOG_LEVEL", "INFO"
).upper()

The default log level for the CLI.

This can be overridden by the GRIFFE_LOG_LEVEL environment variable.

Advanced API¤

patch_loggers ¤

patch_loggers(
    get_logger_func: Callable[[str], Any]
) -> None

Patch Griffe logger and Griffe extensions' loggers.

Parameters:

  • get_logger_func ¤

    (Callable[[str], Any]) –

    A function accepting a name as parameter and returning a logger.