Introspect and display the logger tree inside "logging"
Introspection for the logging logger tree in the Standard Library.
You can install this package with the standard pip command:
$ pip install logging_tree
While you can write programs that call this package’s tree() function and examine the hierarchy of logger objects that it finds inside of the Standard Library logging module, the simplest use of this package for debugging is to call printout() to print the loggers, filters, and handlers that your application has configured:
>>> logging.getLogger('a') >>> logging.getLogger('a.b').setLevel(logging.DEBUG) >>> logging.getLogger('x.c') >>> from logging_tree import printout >>> printout() <--"" Level WARNING | o<--"a" | Level NOTSET so inherits level WARNING | | | o<--"a.b" | Level DEBUG | o<--[x] | o<--"x.c" Level NOTSET so inherits level WARNING
The logger tree should always print successfully, no matter how complicated. A node whose [name] is in square brackets is a “place holder” that has never actually been named in a getLogger() call, but was created automatically to serve as the parent of loggers further down the tree.
There are several interfaces that logging_tree supports, depending on how much detail you need.
Prints the current logger tree, or the tree based at the given node, to the standard output.
Builds and returns the multi-line description of the current logger tree, or the tree based at the given node, as a single string with newlines inside and a newline at the end.
A generator that yields a series of lines that describe the tree based at the given node. Note that the lines are returned without newline terminators attached.
Fetch the current tree of loggers from the logging module. Returns a node, that is simply a tuple with three fields: the logger name ("" for the root logger). the logging.Logger object itself. a list of zero or more child nodes.
I welcome contributions and ideas as this package matures. You can find the bug tracker at the repository page on github. Developers can run this package’s tests with:
$ python -m unittest discover logging_tree
On older versions of Python you will instead have to install unittest2 and use its unit2 command line tool to run the tests.