I use the standard logging library and I need to output DEBUG level messages to the log. But as you know, with the standard setting, the messages of the levels INFO , ERROR , CRITICAL and WARNING will also be logged. And this is not something that I do not need. I need to leave only and only 'DEBUG`.

How to do this?

Asking the old days, Google saw one of the solutions in SO: Python logging: display only information from debug level . But I think the solution should be easier.

Is there it? An easier solution?

UPD I only need to see debug messages during the development process. I want to arrange print () on the code that writes to the debug-log, I don’t feel like it. But during debugging, I’m only interested in specific facts about the algorithm, but instead I get in the appendage and "Vasya came in with IP ..." or "Vasya got a token ...." or "Soon there will not be enough disk for ... "and other messages that are important, but not now. Not in development time!

It is for this reason that you only want to write to the log only and only debug messages. Now I do this with the help of grep, but a lot of its repetition is somehow fed up; (

  • one
    The fact is that in this library the log level of details works “from here and below”: DEBUG> INFO> WARNING> ERROR> CRITICAL. The decision on the link is quite a "simple" and moreover architecturally correct. Most likely you are not using a logger for those purposes. Perhaps you can clarify your task? - maxwell

1 answer 1

I agree with @maxwell, the answer is a working solution. There is one more regular way https://stackoverflow.com/a/879937/4249707 If complexity is measured in the number of lines of code, then we can say that it is simpler :)

  • Yes, but @maxwell wrote in the form of a comment, not an answer! ;) - sys_dev