Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-42644: Validate values in logging.disable() #23786

Merged
merged 2 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,14 @@ def __init__(self, rootnode):
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
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,15 @@ def test_disable(self):
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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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.