1

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?

4
  • This question is similar to: Logging, remove, inspect, and modify handlers configured by fileConfig(). If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Oct 18, 2024 at 13:29
  • Once you find where the messages come from, look into submitting requests or patches upstream to document what loggers are being used. Commented Oct 18, 2024 at 13:47
  • @roganjosh that's quite helpful, although not spot on. stackoverflow.com/a/55400327/865169 helped me identify how I can find the registered loggers in logging.Logger.manager.loggerDict. Commented Oct 19, 2024 at 8:39
  • @chepner stackoverflow.com/a/79102304/865169 shows me how I can reformat log messages to identify where they are coming from. That, together with stackoverflow.com/a/55400327/865169, lets me know which loggers to for example modify the logging level of selectively hide their messages. Commented Oct 19, 2024 at 8:41

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I was hoping for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.