Registry / observability / logbook

logbook

JSON →
library1.10.1pypypi✓ verified 25d ago

Logbook is a Python library designed as a logging replacement, offering a fresh take on logging that is often considered more intuitive and powerful than Python's standard `logging` module. It focuses on clean, contextual logging and robust handler management. The current stable version is 1.9.2, with releases occurring intermittently based on contributions and maintenance.

pip install logbook
INSTALL
IMPORT
SIG · LOGBOOK
L
logbook
observabilitypythonv1.10.1
Install
1.7s avg
Import
90ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.10.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.096s · 19.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.084s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Logger
from logbook import Logger
StreamHandler
from logbook import StreamHandler
FileHandler
from logbook import FileHandler
TimedRotatingFileHandler
from logbook.more import TimedRotatingFileHandler
INFO
from logbook import INFO
DEBUG
from logbook import DEBUG

This quickstart demonstrates basic logging with Logbook using a `Logger` instance and a `StreamHandler` to output messages to standard output. It shows how to use a handler as a context manager (`with ... push_application():`) to ensure proper lifecycle management. Error logging with `log.exception` is also included.

from logbook import Logger, StreamHandler import sys log = Logger('MyApp') def run_app(): log.info('Application started.') log.debug('This is a debug message.') try: 1 / 0 except ZeroDivisionError: log.exception('An error occurred during calculation!') log.info('Application finished.') if __name__ == '__main__': # Handlers should be pushed/popped or used as context managers with StreamHandler(sys.stdout, level='INFO').push_application(): run_app() # Example with a file handler (ensure 'app.log' is writable) # from logbook import FileHandler # with FileHandler('app.log', level='DEBUG').push_application(): # log.info('Logging to file...') # log.debug('This will go to app.log if level is DEBUG or lower.')
Debug
Known issues
breakingLogbook versions 1.x are exclusively for Python 3 (specifically >=3.9 for 1.9.x). Attempting to use a modern Logbook version with Python 2.x or older Python 3 versions will result in `SyntaxError` or other compatibility issues.
fix
Ensure your project uses Python 3.9 or newer. For older Python environments, consider using Logbook 0.12.x or migrating to Python 3.
affects: <1.0 and >=1.0
breakingWhen using handlers with `with handler.push_application():`, `push_application()` is expected to return the handler itself to support the context manager protocol. If `push_application()` unexpectedly returns `None` (e.g., due to an incorrect Logbook version or setup), it will result in a `TypeError: 'NoneType' object does not support the context manager protocol`, causing application crash and preventing any logging. Ensure handlers are correctly pushed/popped or that `push_application()` functions as expected for context management.
fix
Verify your Logbook installation and ensure `push_application()` returns the handler object when used as a context manager. Always use `with` statements for handlers: `with SomeHandler().push_application():`. For application-wide handlers, ensure `push_application()` is called early and `pop_application()` is called on shutdown, or rely on context managers where possible.
affects: All versions
gotchaWhen forking processes, especially with file-based handlers (`FileHandler`, `TimedRotatingFileHandler`), the file descriptors might not be correctly inherited or managed in the child process. This can lead to logs from child processes not being written or corrupting files.
fix
After forking, ensure that file handlers in the child process are explicitly re-opened or re-initialized. The documentation often suggests using `logbook.ThreadsafeFileHandler` and explicitly closing/re-opening in child processes, or using inter-process communication for logging.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'logbook'
The 'logbook' library is not installed in the Python environment, or the Python interpreter cannot find it in its `sys.path`.
fix
Install the 'logbook' package using pip: `pip install logbook`
AttributeError: module 'logbook' has no attribute 'Logger'
The `Logger` class is being incorrectly imported or referenced with a lowercase 'l' (logger) instead of an uppercase 'L' (Logger), or a different attribute is being accessed that does not exist directly on the `logbook` module.
fix
Ensure that the `Logger` class is imported correctly with a capital 'L': `from logbook import Logger`
AttributeError: module 'logbook' has no attribute 'compat'
This error often occurs due to a version mismatch between `logbook` and other libraries that depend on its `compat` module (e.g., `pytest-logbook`), especially when newer versions of `logbook` have removed or refactored this internal module.
fix
Pin the `logbook` version to one compatible with the dependent library (e.g., `pytest-logbook`). A common fix involves downgrading `logbook`: `pip install 'logbook<1.9'` or `pip install 'logbook==1.5.3'` (or a version known to be compatible with your other dependencies).
Upgrade
Version history
1.10.1latest on PyPI · released Aug 5, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
18
OpenAI (training)
2
Resources
logbook — pip install logbook · libregistry