6.29.1 Logger Objects

Python PEP

6.29.1 Logger Objects

Loggers have the following attributes and methods. Note that Loggers are never instantiated directly, but always through the module-level function logging.getLogger(name).

If this evaluates to false, logging messages are not passed by this logger or by child loggers to higher level (ancestor) loggers. The constructor sets this attribute to 1.

Sets the threshold for this logger to lvl. Logging messages which are less severe than lvl will be ignored. When a logger is created, the level is set to NOTSET (which causes all messages to be processed in the root logger, or delegation to the parent in non-root loggers).

Indicates if a message of severity lvl would be processed by this logger. This method checks first the module-level level set by logging.disable(lvl) and then the logger's effective level as determined by getEffectiveLevel().

Indicates the effective level for this logger. If a value other than NOTSET has been set using setLevel(), it is returned. Otherwise, the hierarchy is traversed towards the root until a value other than NOTSET is found, and that value is returned.

Logs a message with level DEBUG on this logger. The msg is the message format string, and the args are the arguments which are merged into msg. The only keyword argument in kwargs which is inspected is exc_info which, if it does not evaluate as false, causes exception information to be added to the logging message. If an exception tuple (as provided by sys.exc_info()) is provided, it is used; otherwise, sys.exc_info() is called to get the exception information.

Logs a message with level INFO on this logger. The arguments are interpreted as for debug().

Logs a message with level WARNING on this logger. The arguments are interpreted as for debug().

Logs a message with level ERROR on this logger. The arguments are interpreted as for debug().

Logs a message with level CRITICAL on this logger. The arguments are interpreted as for debug().

Logs a message with integer level lvl on this logger. The other arguments are interpreted as for debug().

Logs a message with level ERROR on this logger. The arguments are interpreted as for debug(). Exception info is added to the logging message. This method should only be called from an exception handler.

Adds the specified filter filt to this logger.

Removes the specified filter filt from this logger.

Applies this logger's filters to the record and returns a true value if the record is to be processed.

Adds the specified handler hdlr to this logger.

Removes the specified handler hdlr from this logger.

Finds the caller's source filename and line number. Returns the filename and line number as a 2-element tuple.

Handles a record by passing it to all handlers associated with this logger and its ancestors (until a false value of propagate is found). This method is used for unpickled records received from a socket, as well as those created locally. Logger-level filtering is applied using filter().

This is a factory method which can be overridden in subclasses to create specialized LogRecord instances.

See About this document... for information on suggesting changes.