Skip to main content

log_message

Log message using logger based on status_code and logger level.

Pass `request`, `status_code` (if defined) and any provided `extra` as such
to the logging method,

Arguments from `args` will be escaped to avoid potential log injections.
def log_message(
logger: logging.Logger,
message: string,
*args: any,
level: string = null,
status_code: integer = null,
request: HttpRequest = null,
exception: Exception = null,
**extra: any
) - > null

Log message using logger based on status_code and logger level. Pass request, status_code (if defined) and any provided extra as such to the logging method, Arguments from args will be escaped to avoid potential log injections.

Parameters

NameTypeDescription
loggerlogging.LoggerThe logger instance used to emit the log record.
messagestringThe log message format string.
*argsanyPositional arguments to be merged into the message; string values are escaped to prevent log injection.
levelstring = nullThe logging level name (e.g., 'info', 'error'); if omitted, it is inferred from the status_code or defaults to 'info'.
status_codeinteger = nullThe HTTP status code used to determine the default log level (500+ for error, 400+ for warning).
requestHttpRequest = nullThe request object to be included in the log's extra context.
exceptionException = nullAn exception instance to be logged with traceback information via exc_info.
**extraanyAdditional keyword arguments to be included in the log record's extra dictionary.

Returns

TypeDescription
nullThis function does not return a value.