Figuring out which module installs the root log

How do I know which module overrides the Python root log?

My Django project project is imported from several external packages, and I tried to find all instances of the logging.basicConfig and logging.root settings, however most of them are in tests and should not override it unless specifically named.

Django log configuration does not define the root log.

+4
source share
2 answers

Well, the solution was to make some attempts to clear the Python logging module. I just wrapped the decorator around the logging.root.addHandler function, which printed the stack and voila, I found my culprit who called logging.getLogger (). If you call getLogger without any parameters, you get the root log.

import logging import sys import traceback def tracer(func): def new_func(*args, **kwargs): try: traceback.print_stack(sys.stderr) except: traceback.print_exc(sys.stderr) return func(*args, **kwargs) return new_func old_addHandler = logging.root.addHandler logging.root.addHandler = tracer(old_addHandler) # run your code 
+4
source

Do you assume that import logging imports a different import logging module? In this case, there are many special module / package attributes that can help, for example __path__ . The logging.__path__ should tell you where its python imports from.

0
source

Source: https://habr.com/ru/post/1435401/


All Articles