{"id":9903,"library":"logging-tree","title":"Logging Tree","description":"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.","status":"active","version":"1.10","language":"en","source_language":"en","source_url":"https://github.com/brandon-rhodes/logging_tree","tags":["logging","debugging","introspection","diagnostics"],"install":[{"cmd":"pip install logging-tree","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"This is the primary function for displaying the logging tree.","symbol":"printout","correct":"from logging_tree import printout"}],"quickstart":{"code":"import logging\nfrom logging_tree import printout\n\n# Configure some loggers to demonstrate the tree\nroot_logger = logging.getLogger()\nroot_logger.setLevel(logging.INFO)\nroot_logger.addHandler(logging.StreamHandler())\n\napp_logger = logging.getLogger('my_app')\napp_logger.setLevel(logging.DEBUG)\n\nmodule_logger = logging.getLogger('my_app.sub_module')\nmodule_logger.setLevel(logging.WARNING)\n\n# Log some messages to ensure loggers are active\nroot_logger.info('Root logger message')\napp_logger.debug('App logger message')\nmodule_logger.warning('Sub-module logger message')\n\n# Display the logging tree\nprint('\\nLogging Tree:')\nprintout()\n","lang":"python","description":"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."},"warnings":[{"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`.","message":"`printout()` writes to `sys.stdout` by default.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"An 'empty' or minimal tree might be displayed if no named loggers are actively used or configured.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `printout()` directly instead of `main()` for displaying the logging tree.","message":"The `main()` function is deprecated.","severity":"deprecated","affected_versions":"1.9 and above"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install logging-tree` to install the library.","cause":"The `logging-tree` library is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'logging_tree'"},{"fix":"To redirect the output, use the `file` argument: `from io import StringIO; output = StringIO(); printout(file=output); tree_string = output.getvalue()`.","cause":"`logging_tree.printout()` by default sends its output directly to standard output (`sys.stdout`), not through the `logging` system's handlers.","error":"My logging tree output is not appearing in my log file / specific handler output."},{"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.","cause":"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.","error":"The displayed logging tree only shows 'root' and nothing else, even though my application uses logging."}]}