Skip to content

Commit d489ac9

Browse files
committed
Closes python#28524: added default level for logging.disable().
1 parent 8e9c42e commit d489ac9

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Doc/library/logging.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ functions.
10231023
handlers being added multiple times to the root logger, which can in turn
10241024
lead to multiple messages for the same event.
10251025

1026-
.. function:: disable(lvl)
1026+
.. function:: disable(lvl=CRITICAL)
10271027

10281028
Provides an overriding level *lvl* for all loggers which takes precedence over
10291029
the logger's own level. When the need arises to temporarily throttle logging
@@ -1036,6 +1036,14 @@ functions.
10361036
overriding level, so that logging output again depends on the effective
10371037
levels of individual loggers.
10381038

1039+
Note that if you have defined any custom logging level higher than
1040+
``CRITICAL`` (this is not recommended), you won't be able to rely on the
1041+
default value for the *lvl* parameter, but will have to explicitly supply a
1042+
suitable value.
1043+
1044+
.. versionchanged:: 3.7
1045+
The *lvl* parameter was defaulted to level ``CRITICAL``. See Issue
1046+
#28524 for more information about this change.
10391047

10401048
.. function:: addLevelName(lvl, levelName)
10411049

Lib/logging/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ def log(level, msg, *args, **kwargs):
18891889
basicConfig()
18901890
root.log(level, msg, *args, **kwargs)
18911891

1892-
def disable(level):
1892+
def disable(level=CRITICAL):
18931893
"""
18941894
Disable all logging calls of severity 'level' and below.
18951895
"""

Lib/test/test_logging.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3473,6 +3473,11 @@ def test_disable(self):
34733473
logging.disable(83)
34743474
self.assertEqual(logging.root.manager.disable, 83)
34753475

3476+
# test the default value introduced in 3.7
3477+
# (Issue #28524)
3478+
logging.disable()
3479+
self.assertEqual(logging.root.manager.disable, logging.CRITICAL)
3480+
34763481
def _test_log(self, method, level=None):
34773482
called = []
34783483
support.patch(self, logging, 'basicConfig',

0 commit comments

Comments
 (0)