On this page
logging.LogRecord
Prev: logging.LoggerAdapter | Up: logging | Next: logging.makeLogRecord
Rel: logging.addLevelName, logging.basicConfig, logging.BufferingFormatter, logging.captureWarnings
Ref: docs.python.org — logging.LogRecord
Tags: #public #python3 #stdlib #logging
Import
import logging
from logging import LogRecord
Signature & Overview
logging.LogRecord(name, level, pathname, lineno, msg, args, exc_info, func=None, sinfo=None, **kwargs)
A LogRecord instance represents an event being logged.
Methods & Attributes
LogRecord.getMessage(self)— Return the message for this LogRecord.
Usage
import logging
rec = logging.LogRecord("app", logging.ERROR, "main.py", 42, "failed: %s", ("timeout",), None)
assert rec.getMessage() == "failed: timeout" and rec.levelname == "ERROR"
Gotchas
- Avoid mutating reserved attribute names via
extra=: Passingextra={"message": ...}orextra={"name": ...}tologger.info()raisesKeyErrorbecauseLogRecordalready owns those fields.
REPL Inspect
from logging import LogRecord
help(LogRecord)
Linked from
Related notes
- tuts/python3/stdlib_module/logging/LoggerAdapter Linked here; links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/makeLogRecord Linked here; links to this page; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/logging/addLevelName Linked here; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/basicConfig Linked here; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/BufferingFormatter Linked here; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/captureWarnings Linked here; shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/critical shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/debug shared tags: #logging, #stdlib
- tuts/python3/stdlib_module/logging/disable shared tags: #logging, #stdlib