Finding out which module is setting the root logger
Question: How would I be able to find which module is overriding the Python root logger?

My Django project imports from quite a few external packages, and I have tried
searching for all instances of logging.basicConfig and logging.root setups,
however most of them are in tests and should not be overriding it unless
specifically called.

Django's logging config does not specify a root logger.


Answer: Well the solution was to do some monkey patching of the Python logging module.
I just wrapped a decorator around the logging.root.addHandler function that
printed the stack and voila, I found my culprit who was calling
logging.getLogger(). If you call getLogger without any parameters, you get the
root logger.

    
    
    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
    

