# Logbook

### Navigation

- index
- modules |
- next |
- previous |
- Logbook 0.6.1-dev »
- API Documentation »

# 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`(_cls=<class 'logbook._fallback._StackBound'>)

    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`(_cls=<class 'logbook._fallback._StackBound'>)

    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` None

    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()

  `critical`(*args, **kwargs)

    Logs a `LogRecord` with the level set to `CRITICAL`.

  `debug`(*args, **kwargs)

    Logs a `LogRecord` with the level set to `DEBUG`.

  `error`(*args, **kwargs)

    Logs a `LogRecord` with the level set to `ERROR`.

  `exception`(*args, **kwargs)

    Works exactly like `error()` just that the message is optional and exception information is recorded.

  `info`(*args, **kwargs)

    Logs a `LogRecord` with the level set to `INFO`.

  `level_name` None

    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.``RotatingFileHandlerBase`(*args, **kwargs)

  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`()

    Called if `should_rollover()` returns True and has to perform the actual rollover.

  `should_rollover`(record, formatted_record)

    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)

  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` None

    the currently attached format string as new-style format string.

  `formatter_class`

    the class to be used for string formatting

    alias of `StringFormatter`

### Navigation

- index
- modules |
- next |
- previous |
- Logbook 0.6.1-dev »
- API Documentation »