pythonpython-logging

Python logging: where are messages coming from


I have an application using lots of different packages and many of them are logging output. I would like to clean up my application's logs and perhaps disable some of the other packages' output. My problem is that I do not know where many of these log messages are coming from. Can I configure / turn something on in Python's logging at a global level that lets me identify where the messages are coming from?


Solution

  • You can try the following custom approach to identify where the logs are coming from

    import logging
    
    # Configure logging globally
    logging.basicConfig(
        level=logging.DEBUG,  # adjust the log level as per your requirements
        format='%(asctime)s %(name)s %(module)s.%(funcName)s +%(lineno)s: %(levelname)-8s [%(process)d] %(message)s',
    )
    

    After this, you should be able to see some details about where the logs are coming from.