Python Glossary Русский

all Python 3loggingterm

logging.LogRecord

records and filters

A log record: an object holding the message, level, logger name, time, file and line of the call. Filters and formatters receive it.

Syntax

LogRecord(name, level, pathname, lineno, msg, args, exc_info, func=None, sinfo=None)

The template and its arguments are kept apart (msg and args) and merged only in getMessage(), so logger.info('%s', x) costs no formatting when the level is off. A broken template such as info('%s %s', 1) raises nothing in your code: logging prints '--- Logging error ---' to stderr and drops the line. You do not build a LogRecord yourself — the logger does, and tests use makeLogRecord().

Examples

import logging
def show(record):
    print(record.name, record.levelname, repr(record.msg), record.args, record.getMessage())
    return False  # дальше не пускать
log = logging.getLogger('shop')
log.addFilter(show)
log.warning('остаток %d шт.', 3)  # → shop WARNING 'остаток %d шт.' (3,) остаток 3 шт.

See also

Open in the full glossarydocs.python.orgReport an inaccuracy