Skip to main content

Introspect and display the logger tree inside "logging"

Project description

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.

logging_tree.printout(node=None)

Prints the current logger tree, or the tree based at the given node, to the standard output.

logging_tree.format.build_description(node=None)

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.

logging_tree.format.describe(node)

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.

logging_tree.tree()

Fetch the current tree of loggers from the logging module. Returns a node, that is simply a tuple with three fields:

[0] the logger name ("" for the root logger).
[1] the logging.Logger object itself.
[2] 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.

Changelog

Version 1.8 - 2018 August 5

Improve the output to better explain what happens if a “parent” attribute has been set to None.

Version 1.7 - 2016 January 23

Detect whether each logger has the correct “parent” attribute and, if not, print where its log messages are being sent instead.

Version 1.6 - 2015 January 8

Fixed a crash that would occur if a custom logging Formatter was missing its format string attributes.

Version 1.5 - 2014 December 24

Handlers now display their logging level if one has been set, and their custom logging formatter if one has been installed.

Version 1.4 - 2014 January 8

Thanks to a contribution from Dave Brondsema, disabled loggers are now actually marked as “Disabled” to make it less of a surprise that they fail to log anything.

Version 1.3 - 2013 October 29

Be explicit and display the logger level NOTSET along with the effective level inherited from the logger’s ancestors; and display the list of .filters of a custom logging handler even though it might contain custom code that ignores them.

Version 1.2 - 2013 January 19

Compatible with Python 3.3 thanks to @ralphbean.

Version 1.1 - 2012 February 17

Now compatible with 2.3 <= Python <= 3.2.

Version 1.0 - 2012 February 13

Can display the handler inside a MemoryHandler; entire public interface documented; 100% test coverage.

Version 0.6 - 2012 February 10

Added a display format for every logging.handlers class.

Version 0.5 - 2012 February 8

Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logging_tree-1.8.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

logging_tree-1.8-py2.py3-none-any.whl (11.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file logging_tree-1.8.tar.gz.

File metadata

  • Download URL: logging_tree-1.8.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for logging_tree-1.8.tar.gz
Algorithm Hash digest
SHA256 dc6cf63f2f8e7805dad32b3400fb9685c9d3cf83bd0f0e99267e426b9cf72694
MD5 749ca9fea3bc5e2f3d3c0cf8f9bb39de
BLAKE2b-256 6d4a17b0bf13bf8d0ec7df1ec54ded2a96689e7559f0a79b269087f34455ae3b

See more details on using hashes here.

File details

Details for the file logging_tree-1.8-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for logging_tree-1.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 668c5c364f4623e81784e6042e82fb87d9423bd291a68933c7a3c03e72f4f343
MD5 4b8cb66287961da96f1898f9f84170b7
BLAKE2b-256 c8c2ef440ebd44b0106a3b49026e0191a78fc1bfd4daf24aaa4f68d1901b6763

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page