Python Glossary Русский

all Python 3loggingfunction

logging.makeLogRecord()

records and filters

Creates a LogRecord from a dict of attributes. Used to rebuild a record sent over the network and in tests of filters and formatters.

Syntax

record = logging.makeLogRecord(attrdict)

The dict's attributes are simply written over a blank record and are not reconciled: levelno=40 does not set levelname, and the formatter prints 'Level None'. So tests pass both fields. The logger name and file are not filled in either — name stays None, and created is the moment makeLogRecord() was called.

Examples

import logging
fmt = logging.Formatter('%(levelname)s %(message)s')
r = logging.makeLogRecord({'msg': 'id=%s', 'args': (7,), 'levelno': 40})
print(fmt.format(r))  # → Level None id=7
r = logging.makeLogRecord({'msg': 'ok', 'levelno': 40, 'levelname': 'ERROR'})
print(fmt.format(r), r.name)  # → ERROR ok None

See also

Open in the full glossarydocs.python.orgReport an inaccuracy