Internal API¶
This documents the internal API that might be useful for more advanced setups or custom handlers.
-
logbook.base.
dispatch_record
(record)[source]¶ Passes a record on to the handlers on the stack. This is useful when log records are created programmatically and already have all the information attached and should be dispatched independent of a logger.
-
class
logbook.base.
StackedObject
[source]¶ Baseclass for all objects that provide stack manipulation operations.
-
class
logbook.base.
RecordDispatcher
(name=None, level=0)[source]¶ A record dispatcher is the internal base class that implements the logic used by the
Logger
.-
call_handlers
(record)[source]¶ Pass a record to all relevant handlers in the following order:
- per-dispatcher handlers are handled first
- afterwards all the current context handlers in the order they were pushed
Before the first handler is invoked, the record is processed (
process_record()
).
-
group
= None¶ optionally the name of the group this logger belongs to
-
handle
(record)[source]¶ Call the handlers for the specified record. This is invoked automatically when a record should be handled. The default implementation checks if the dispatcher is disabled and if the record level is greater than the level of the record dispatcher. In that case it will call the handlers (
call_handlers()
).
-
handlers
= None¶ list of handlers specific for this record dispatcher
-
level
¶ the level of the record dispatcher as integer
-
make_record_and_handle
(level, msg, args, kwargs, exc_info, extra)[source]¶ Creates a record from some given arguments and heads it over to the handling system.
-
name
= None¶ the name of the record dispatcher
-
process_record
(record)[source]¶ Processes the record with all context specific processors. This can be overriden to also inject additional information as necessary that can be provided by this record dispatcher.
-
suppress_dispatcher
= False¶ If this is set to True the dispatcher information will be suppressed for log records emitted from this logger.
-
-
class
logbook.base.
LoggerMixin
[source]¶ This mixin class defines and implements the “usual” logger interface (i.e. the descriptive logging functions).
Classes using this mixin have to implement a
handle()
method which takes aLogRecord
and passes it along.-
catch_exceptions
(*args, **kwargs)[source]¶ A context manager that catches exceptions and calls
exception()
for exceptions caught that way. Example:with logger.catch_exceptions(): execute_code_that_might_fail()
-
exception
(*args, **kwargs)[source]¶ Works exactly like
error()
just that the message is optional and exception information is recorded.
-
level_name
¶ The name of the minimium logging level required for records to be created.
-
log
(level, *args, **kwargs)[source]¶ Logs a
LogRecord
with the level set to the level parameter. Because custom levels are not supported by logbook, this method is mainly used to avoid the use of reflection (e.g.:getattr()
) for programmatic logging.
-
-
class
logbook.handlers.
RotatingFileHandlerBase
(*args, **kwargs)[source]¶ Baseclass for rotating file handlers.
Changed in version 0.3: This class was deprecated because the interface is not flexible enough to implement proper file rotations. The former builtin subclasses no longer use this baseclass.
-
perform_rollover
()[source]¶ Called if
should_rollover()
returns True and has to perform the actual rollover.
-
should_rollover
(record, formatted_record)[source]¶ Called with the log record and the return value of the
format_and_encode()
method. The method has then to return True if a rollover should happen or False otherwise.Changed in version 0.3: Previously this method was called with the number of bytes returned by
format_and_encode()
-
-
class
logbook.handlers.
StringFormatterHandlerMixin
(format_string)[source]¶ A mixin for handlers that provides a default integration for the
StringFormatter
class. This is used for all handlers by default that log text to a destination.-
default_format_string
= u'[{record.time:%Y-%m-%d %H:%M}] {record.level_name}: {record.channel}: {record.message}'¶ a class attribute for the default format string to use if the constructor was invoked with None.
-
format_string
¶ the currently attached format string as new-style format string.
-
formatter_class
¶ the class to be used for string formatting
alias of
StringFormatter
-