Solvedloguru How to set the log level?

It's strange for something that is supposed to be stupidly simple there is no setLevel() function available, as on the plain old logger I get back from getLogger().

The docs show a heavy handed approach of adding a whole new handler just to set the level like:

logger.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="INFO")

But really?

16 Answers

✔️Accepted Answer

I you would like to use another level in place of the default "DEBUG", you can just set the LOGURU_LEVEL environment variable to the severity level your prefer.

Alternatively, you can just re-add the stderr handler with the appropriate level, you don't need to modify the format and filter attributes:

logger.add(sys.stderr, level="INFO")

Other Answers:

The thing to understand is that, contrary to standard logging, the Loguru's logger is not associated to any level: only handlers are. So, there is no setLevel() function because it would not make sense. The handlers are the sole master of the logs severity they accept.

More Issues: