Skip to content

loggers ¤

Logging functions.

Classes:

Functions:

LoggerAdapter ¤

LoggerAdapter(prefix: str, logger: Logger)

Bases: LoggerAdapter

A logger adapter to prefix messages.

This adapter also adds an additional parameter to logging methods called once: if True, the message will only be logged once.

Examples:

In Python code:

>>> logger = get_logger("myplugin")
>>> logger.debug("This is a debug message.")
>>> logger.info("This is an info message.", once=True)

In Jinja templates (logger available in context as log):

{{ log.debug("This is a debug message.") }}
{{ log.info("This is an info message.", once=True) }}

Parameters:

  • prefix ¤

    (str) –

    The string to insert in front of every message.

  • logger ¤

    (Logger) –

    The logger instance.

Methods:

  • log

    Log a message.

  • process

    Process the message.

log ¤

log(
    level: int, msg: object, *args: object, **kwargs: object
) -> None

Log a message.

Parameters:

  • level ¤

    (int) –

    The logging level.

  • msg ¤

    (object) –

    The message.

  • *args ¤

    (object, default: () ) –

    Additional arguments passed to parent method.

  • **kwargs ¤

    (object, default: {} ) –

    Additional keyword arguments passed to parent method.

process ¤

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

Process the message.

Parameters:

Returns:

TemplateLogger ¤

TemplateLogger(logger: LoggerAdapter)

A wrapper class to allow logging in templates.

The logging methods provided by this class all accept two parameters:

  • msg: The message to log.
  • once: If True, the message will only be logged once.

Methods:

  • debug

    Function to log a DEBUG message.

  • info

    Function to log an INFO message.

  • warning

    Function to log a WARNING message.

  • error

    Function to log an ERROR message.

  • critical

    Function to log a CRITICAL message.

Parameters:

get_logger ¤

get_logger(name: str) -> LoggerAdapter

Return a pre-configured logger.

Parameters:

  • name ¤

    (str) –

    The name to use with logging.getLogger.

Returns:

get_template_logger ¤

get_template_logger(
    handler_name: str | None = None,
) -> TemplateLogger

Return a logger usable in templates.

Parameters:

  • handler_name ¤

    (str | None, default: None ) –

    The name of the handler.

Returns:

get_template_logger_function ¤

get_template_logger_function(
    logger_func: Callable,
) -> Callable

Create a wrapper function that automatically receives the Jinja template context.

Parameters:

  • logger_func ¤

    (Callable) –

    The logger function to use within the wrapper.

Returns:

get_template_path ¤

get_template_path(context: Context) -> str

Return the path to the template currently using the given context.

Parameters:

  • context ¤

    (Context) –

    The template context.

Returns:

  • str

    The relative path to the template.