Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I dump Python's logging configuration?

How do I dump the current configuration of the Python logging module? For example, if I use a module that configures logging for me, how can I see what it has done?

like image 889
rgov Avatar asked Oct 26 '25 09:10

rgov


1 Answers

There does not appear to be a documented way to do so, but we can get hints by looking at how the logging module is implemented.

All Loggers belong to a tree, with the root Logger instance at logging.root. The Logger instances do not track their own children but instead have a shared Manager that can be used to get a list of all loggers:

>>> print(logging.root.manager.loggerDict)
{
  'rosgraph': <logging.PlaceHolder object at 0xffffa2851710>,
  'rosgraph.network': <logging.Logger object at 0xffffa28517d0>,
  'rosout': <rosgraph.roslogging.RospyLogger object at 0xffffa2526290>,
  'rospy': <rosgraph.roslogging.RospyLogger object at 0xffffa2594250>,
  ...
}

Each Logger instance has handlers and filters attributes which can help understand the behavior of the logger.

like image 53
rgov Avatar answered Oct 29 '25 08:10

rgov