How can I remove / inspect / modify handlers configured for my loggers using the fileConfig() function?
For removing there is Logger.removeHandler(hdlr) method, but how
The answer by @Mickey-Perlstein was just what I was looking for, but the listing appears to come from a much more complete version than the code provided.
This code is kind of even cruder, but crucially for my use and understanding, includes the root logger
import logging
def listloggers():
rootlogger = logging.getLogger()
print(rootlogger)
for h in rootlogger.handlers:
print(' %s' % h)
for nm, lgr in logging.Logger.manager.loggerDict.items():
print('+ [%-20s] %s ' % (nm, lgr))
if not isinstance(lgr, logging.PlaceHolder):
for h in lgr.handlers:
print(' %s' % h)
output:
(DEBUG)>
+ [concurrent.futures ]
+ [concurrent ]
+ [asyncio ]
+ [myapp ]
+ [flask.app ]
+ [flask ]
+ [werkzeug ]