class logging.LogRecord(name, level, pathname, lineno, msg, args, exc_info, func=None, sinfo=None)
Contains all the information pertinent to the event being logged.
The primary information is passed in msg
and args
, which are combined using msg % args
to create the message
field of the record.
Parameters: |
|
---|
-
getMessage()
-
Returns the message for this
LogRecord
instance after merging any user-supplied arguments with the message. If the user-supplied message argument to the logging call is not a string,str()
is called on it to convert it to a string. This allows use of user-defined classes as messages, whose__str__
method can return the actual format string to be used.
Changed in version 3.2: The creation of a LogRecord
has been made more configurable by providing a factory which is used to create the record. The factory can be set using getLogRecordFactory()
and setLogRecordFactory()
(see this for the factory’s signature).
This functionality can be used to inject your own values into a LogRecord at creation time. You can use the following pattern:
old_factory = logging.getLogRecordFactory() def record_factory(*args, **kwargs): record = old_factory(*args, **kwargs) record.custom_attribute = 0xdecafbad return record logging.setLogRecordFactory(record_factory)
With this pattern, multiple factories could be chained, and as long as they don’t overwrite each other’s attributes or unintentionally overwrite the standard attributes listed above, there should be no surprises.
Please login to continue.