-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Description
Feature or enhancement
Proposal:
The logging
library provides methods with various severity levels from info to critical, and lets you set a log level so that messages with less than that severity won't be printed. But sometimes (particularly when the thing you want to log about is the logging configuration itself) you'd like to unconditionally log a message, no matter what the current log level.
import logging
l = logging.getLogger()
mylevel = logging.ERROR
l.setLevel(mylevel)
# At this point I would like to unconditionally log:
l.unconditional(f'Set log severity level to {mylevel}')
# This message will always be printed, no matter what level has been configured.
Now, I could call critical
to make sure the message gets printed, but that seems wrong somehow, as it's not "a serious error" as the documentation of level CRITICAL
states. It's simply a message that I want to always output, because it describes the kind of messages that will be logged from now on.
Another example might be if you want to definitely print something just after opening a new log source, just to make sure it works before continuing with the application. (If there might be socket errors or file permission errors on writing, better to hit those immediately.) Again, it's not a critical message, but you want to ensure it will be output every time.
While you could save the existing severity, downgrade to INFO
, call the info
method and then put the severity back, I think it is simpler and more explicit for logging to provide a method that will always log. It should be used sparingly, of course.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response