loggers ¤
Logging functions.
Classes:
-
LoggerAdapter
–A logger adapter to prefix messages.
-
TemplateLogger
–A wrapper class to allow logging in templates.
Functions:
-
get_logger
–Return a pre-configured logger.
-
get_template_logger
–Return a logger usable in templates.
-
get_template_logger_function
–Create a wrapper function that automatically receives the Jinja template context.
-
get_template_path
–Return the path to the template currently using the given context.
LoggerAdapter ¤
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 ¤
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
: IfTrue
, 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:
-
logger
¤LoggerAdapter
) –A logger adapter.
get_logger ¤
get_logger(name: str) -> LoggerAdapter
Return a pre-configured logger.
Parameters:
Returns:
-
LoggerAdapter
–A logger configured to work well in MkDocs.
get_template_logger ¤
get_template_logger(
handler_name: str | None = None,
) -> TemplateLogger
get_template_logger_function ¤
get_template_logger_function(
logger_func: Callable,
) -> Callable