Internal API
This documents the internal API that might be useful for more advanced setups or custom handlers.
- logbook.base.dispatch_record(record)
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
Baseclass for all objects that provide stack manipulation operations.
- applicationbound()
Can be used in combination with the with statement to execute code while the object is bound to the application.
- pop_application()
Pops the stacked object from the application stack.
- pop_thread()
Pops the stacked object from the thread stack.
- push_application()
Pushes the stacked object to the application stack.
- push_thread()
Pushes the stacked object to the thread stack.
- threadbound()
Can be used in combination with the with statement to execute code while the object is bound to the thread.
- class logbook.base.RecordDispatcher(name=None, level=0)
A record dispatcher is the internal base class that implements the logic used by the Logger.
- call_handlers(record)
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)
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)
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)
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
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 a LogRecord and passes it along.
- catch_exceptions(*args, **kwargs)
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)
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)
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.
- notice(*args, **kwargs)
Logs a LogRecord with the level set to NOTICE.
- warn(*args, **kwargs)
Logs a LogRecord with the level set to WARNING. This function has an alias named warning().
- warning(*args, **kwargs)
Alias for warn().
- class logbook.handlers.StringFormatterHandlerMixin(format_string)
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:%S.%f}] {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