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:
Source code in src/mkdocstrings/loggers.py
48 49 50 51 52 53 54 55 56 57 |
|
log ¤
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.
Source code in src/mkdocstrings/loggers.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
process ¤
Process the message.
Parameters:
Returns:
Source code in src/mkdocstrings/loggers.py
59 60 61 62 63 64 65 66 67 68 69 |
|
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.
Source code in src/mkdocstrings/loggers.py
104 105 106 107 108 109 110 111 112 113 114 |
|
get_logger ¤
get_logger(name: str) -> LoggerAdapter
Return a pre-configured logger.
Parameters:
Returns:
-
LoggerAdapter
–A logger configured to work well in MkDocs.
Source code in src/mkdocstrings/loggers.py
167 168 169 170 171 172 173 174 175 176 177 |
|
get_template_logger ¤
get_template_logger(
handler_name: str | None = None,
) -> TemplateLogger
Return a logger usable in templates.
Parameters:
Returns:
-
TemplateLogger
–A template logger.
Source code in src/mkdocstrings/loggers.py
180 181 182 183 184 185 186 187 188 189 190 |
|
get_template_logger_function ¤
get_template_logger_function(
logger_func: Callable,
) -> Callable
Create a wrapper function that automatically receives the Jinja template context.
Parameters:
Returns:
-
Callable
–A function.
Source code in src/mkdocstrings/loggers.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
get_template_path ¤
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.
Source code in src/mkdocstrings/loggers.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|