You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Set default argument of logging.disable() to logging.CRITICAL #72710
As a convenience, we could make the default argument for logging.disable()'s lvl argument as logging.CRITICAL. This would make disabling all logging messages:
Given that a user can add their on levels, I think that having a default would be misleading (having no arguments implies total disabling but with custom levels the default of CRITICAL might not disable all messages).
AlSweigart commented on Oct 25, 2016
AlSweigartmannequin
MannequinAuthor
More actions
xiang.zhang: The use case I've found is that I often have logging enabled while writing code, and then want to shut it off once I've finished. This might not be everyone's use case, but this is a backwards-compatible change since it's currently a required argument. If there's a sensible default, I think this is it.
rhettinger: We could use sys.maxsize instead of logging.CRITICAL to disable any custom logging levels as well if this is a concern.
We could use sys.maxsize instead of logging.CRITICAL to disable any custom logging levels as well if this is a concern.
sys.maxsize is not the upper bound limit of integers in Python. There is no such value in Python3.
The use case I've found is that I often have logging enabled while writing code, and then want to shut it off once I've finished.
How about logger.disabled = True. This can work even if there are custom levels. But it's not a documented feature.
AlSweigart commented on Oct 25, 2016
AlSweigartmannequin
MannequinAuthor
More actions
How about logger.disabled = True.
This seems to violate "there should be one and only one way to do it". What happens when logging.disabled is True but then logging.disable(logging.NOTSET) is called? I could see this being a gotcha.
Since logging.CRITICAL is 50, I think it's reasonable to assume that no one would create a logging level larger than sys.maxsize.
Put me down for -0. I don't think the minor convenience is worth the loss in clarity.
AlSweigart commented on Oct 25, 2016
AlSweigartmannequin
MannequinAuthor
More actions
As a general indicator, I did a google search for "logging.disable(logging.XXX)" for the different levels. The number of results passing ERROR, WARN, DEBUG, and INFO are under a couple dozen each. But the number of results for "logging.disable(logging.CRITICAL)" is 3,800.
It's a rough estimate, but it shows that 95%+ of the time people call logging.disable() they want to disable all logging.
The use case I've found is that I often have logging enabled while writing code, and then want to shut it off once I've finished.
You could do this by having a configuration which is quite verbose while doing development and then less verbose when in production mode. Then if an issue crops up in production, verbosity could be temporarily turned up in the production configuration while diagnosing the issue, then turned down again later, without making code changes. Remember that verbosity can be set at the handler level too, which sometimes gives finer-grained control of logging verbosity.
AlSweigart commented on Nov 6, 2016
AlSweigartmannequin
MannequinAuthor
More actions
Setting up different configurations for dev/prod is a bit more complicated than I'd like for most projects. I'd instead just call logging.disable(logging.CRITICAL).
The entire point of this is just for the convenience of being able to disable logging messages by calling logging.disable() instead of logging.disable(logging.CRITICAL).
It's a two-line change, backwards compatible, and (imo) a sensible default. You call logging.disable() expecting it to disable logging. You might want to disable a lower level, but as the Google search shows, most people just want to disable all logging period.
Activity
AlSweigart commentedon Oct 24, 2016
As a convenience, we could make the default argument for logging.disable()'s lvl argument as logging.CRITICAL. This would make disabling all logging messages:
...instead of the more verbose:
This one-line change is backwards compatible.
zhangyangyu commentedon Oct 25, 2016
Is disabling all logging messages a common need? Maybe other levels are common but we can't know.
And at least the doc patch needs a versionchanged tag.
rhettinger commentedon Oct 25, 2016
Given that a user can add their on levels, I think that having a default would be misleading (having no arguments implies total disabling but with custom levels the default of CRITICAL might not disable all messages).
AlSweigart commentedon Oct 25, 2016
xiang.zhang: The use case I've found is that I often have logging enabled while writing code, and then want to shut it off once I've finished. This might not be everyone's use case, but this is a backwards-compatible change since it's currently a required argument. If there's a sensible default, I think this is it.
rhettinger: We could use sys.maxsize instead of logging.CRITICAL to disable any custom logging levels as well if this is a concern.
zhangyangyu commentedon Oct 25, 2016
sys.maxsize is not the upper bound limit of integers in Python. There is no such value in Python3.
How about logger.disabled = True. This can work even if there are custom levels. But it's not a documented feature.
AlSweigart commentedon Oct 25, 2016
This seems to violate "there should be one and only one way to do it". What happens when logging.disabled is True but then logging.disable(logging.NOTSET) is called? I could see this being a gotcha.
Since logging.CRITICAL is 50, I think it's reasonable to assume that no one would create a logging level larger than sys.maxsize.
rhettinger commentedon Oct 25, 2016
Put me down for -0. I don't think the minor convenience is worth the loss in clarity.
AlSweigart commentedon Oct 25, 2016
As a general indicator, I did a google search for "logging.disable(logging.XXX)" for the different levels. The number of results passing ERROR, WARN, DEBUG, and INFO are under a couple dozen each. But the number of results for "logging.disable(logging.CRITICAL)" is 3,800.
It's a rough estimate, but it shows that 95%+ of the time people call logging.disable() they want to disable all logging.
vsajip commentedon Oct 30, 2016
You could do this by having a configuration which is quite verbose while doing development and then less verbose when in production mode. Then if an issue crops up in production, verbosity could be temporarily turned up in the production configuration while diagnosing the issue, then turned down again later, without making code changes. Remember that verbosity can be set at the handler level too, which sometimes gives finer-grained control of logging verbosity.
AlSweigart commentedon Nov 6, 2016
Setting up different configurations for dev/prod is a bit more complicated than I'd like for most projects. I'd instead just call logging.disable(logging.CRITICAL).
The entire point of this is just for the convenience of being able to disable logging messages by calling logging.disable() instead of logging.disable(logging.CRITICAL).
It's a two-line change, backwards compatible, and (imo) a sensible default. You call logging.disable() expecting it to disable logging. You might want to disable a lower level, but as the Google search shows, most people just want to disable all logging period.
python-dev commentedon Dec 31, 2016
New changeset 459500606560 by Vinay Sajip in branch 'default':
Closes bpo-28524: added default level for logging.disable().
https://hg.python.org/cpython/rev/459500606560