Registry / observability / logging-tree

logging-tree

JSON →
library1.10pypypi✓ verified 85d ago

The `logging-tree` library provides a simple way to introspect and display the logger hierarchy from Python's built-in `logging` module. It helps developers visualize how loggers are configured, including their levels and handlers. The current version is 1.10, with releases occurring periodically to add minor features or address issues.

pip install logging-tree
INSTALL
IMPORT
SIG · LOGGING-TREE
L
logging-tree
observabilitypythonv1.10
Install
1.6s avg
Import
34ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.10 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.035s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.032s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

printout
from logging_tree import printout
This is the primary function for displaying the logging tree.

This example configures a basic logging hierarchy and then uses `logging_tree.printout()` to display the structure of all active loggers, their levels, and handlers.

import logging from logging_tree import printout # Configure some loggers to demonstrate the tree root_logger = logging.getLogger() root_logger.setLevel(logging.INFO) root_logger.addHandler(logging.StreamHandler()) app_logger = logging.getLogger('my_app') app_logger.setLevel(logging.DEBUG) module_logger = logging.getLogger('my_app.sub_module') module_logger.setLevel(logging.WARNING) # Log some messages to ensure loggers are active root_logger.info('Root logger message') app_logger.debug('App logger message') module_logger.warning('Sub-module logger message') # Display the logging tree print('\nLogging Tree:') printout()
Debug
Known issues
gotcha`printout()` writes to `sys.stdout` by default.
fix
If you need to capture the output, pass a `file` object to `printout()`, e.g., `printout(file=my_file_object)`, or redirect `sys.stdout`.
affects: All versions
gotchaAn 'empty' or minimal tree might be displayed if no named loggers are actively used or configured.
fix
Ensure that your application explicitly retrieves and potentially configures named loggers (e.g., `logging.getLogger('my_app')`) before calling `printout()` to see a detailed tree.
affects: All versions
deprecatedThe `main()` function is deprecated.
fix
Use `printout()` directly instead of `main()` for displaying the logging tree.
affects: 1.9 and above
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'logging_tree'
The `logging-tree` library is not installed in your Python environment.
fix
Run `pip install logging-tree` to install the library.
My logging tree output is not appearing in my log file / specific handler output.
`logging_tree.printout()` by default sends its output directly to standard output (`sys.stdout`), not through the `logging` system's handlers.
fix
To redirect the output, use the `file` argument: `from io import StringIO; output = StringIO(); printout(file=output); tree_string = output.getvalue()`.
The displayed logging tree only shows 'root' and nothing else, even though my application uses logging.
While your application may use logging, it might only be using the root logger or loggers that haven't been explicitly retrieved with `logging.getLogger('name')`, or your `printout()` call happens before loggers are fully initialized.
fix
Ensure that named loggers are created and active before calling `printout()`. Also, verify that you are indeed defining distinct loggers beyond the root. For example, explicitly call `logging.getLogger('my_app')` at some point in your code.
Upgrade
Version history
1.10latest on PyPI · released May 3, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
logging-tree — pip install logging-tree · libregistry