aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--Lib/logging/__init__.py8
-rw-r--r--Lib/test/test_logging.py9
-rw-r--r--Misc/NEWS.d/next/Library/2020-12-15-10-00-04.bpo-42644.XgLCNx.rst3
3 files changed, 20 insertions, 0 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index badfd654b16..50b7378cd63 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1289,6 +1289,14 @@ class Manager(object):
self.loggerClass = None
self.logRecordFactory = None
+ @property
+ def disable(self):
+ return self._disable
+
+ @disable.setter
+ def disable(self, value):
+ self._disable = _checkLevel(value)
+
def getLogger(self, name):
"""
Get a logger with the specified name (channel name), creating it
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index e2196736dcd..859baa4738b 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -4219,6 +4219,15 @@ class ModuleLevelMiscTest(BaseTest):
logging.disable(83)
self.assertEqual(logging.root.manager.disable, 83)
+ self.assertRaises(ValueError, logging.disable, "doesnotexists")
+
+ class _NotAnIntOrString:
+ pass
+
+ self.assertRaises(TypeError, logging.disable, _NotAnIntOrString())
+
+ logging.disable("WARN")
+
# test the default value introduced in 3.7
# (Issue #28524)
logging.disable()
diff --git a/Misc/NEWS.d/next/Library/2020-12-15-10-00-04.bpo-42644.XgLCNx.rst b/Misc/NEWS.d/next/Library/2020-12-15-10-00-04.bpo-42644.XgLCNx.rst
new file mode 100644
index 00000000000..f58b58e4002
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-12-15-10-00-04.bpo-42644.XgLCNx.rst
@@ -0,0 +1,3 @@
+`logging.disable` will now validate the types and value of its parameter. It
+also now accepts strings representing the levels (as does `loging.setLevel`)
+instead of only the numerical values.