summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2015-01-23 19:52:21 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2015-01-23 19:52:21 (GMT)
commit5abca7023c06dbe77a974d060e5d0e81d7785709 (patch)
tree1a97cf5bb3d566360dcb951a4080213f69c192ad /Lib/logging
parent71e72960169dbcacc3c62cef7e024f3b1cd95f2e (diff)
downloadcpython-5abca7023c06dbe77a974d060e5d0e81d7785709.zip
cpython-5abca7023c06dbe77a974d060e5d0e81d7785709.tar.gz
cpython-5abca7023c06dbe77a974d060e5d0e81d7785709.tar.bz2
Issue #23207: logging.basicConfig() now does additional validation of its arguments.
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/__init__.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 7fb3a35..9a8685b 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1723,7 +1723,7 @@ def basicConfig(**kwargs):
_acquireLock()
try:
if len(root.handlers) == 0:
- handlers = kwargs.get("handlers")
+ handlers = kwargs.pop("handlers", None)
if handlers is None:
if "stream" in kwargs and "filename" in kwargs:
raise ValueError("'stream' and 'filename' should not be "
@@ -1733,28 +1733,31 @@ def basicConfig(**kwargs):
raise ValueError("'stream' or 'filename' should not be "
"specified together with 'handlers'")
if handlers is None:
- filename = kwargs.get("filename")
+ filename = kwargs.pop("filename", None)
if filename:
- mode = kwargs.get("filemode", 'a')
+ mode = kwargs.pop("filemode", 'a')
h = FileHandler(filename, mode)
else:
- stream = kwargs.get("stream")
+ stream = kwargs.pop("stream", None)
h = StreamHandler(stream)
handlers = [h]
- dfs = kwargs.get("datefmt", None)
- style = kwargs.get("style", '%')
+ dfs = kwargs.pop("datefmt", None)
+ style = kwargs.pop("style", '%')
if style not in _STYLES:
raise ValueError('Style must be one of: %s' % ','.join(
_STYLES.keys()))
- fs = kwargs.get("format", _STYLES[style][1])
+ fs = kwargs.pop("format", _STYLES[style][1])
fmt = Formatter(fs, dfs, style)
for h in handlers:
if h.formatter is None:
h.setFormatter(fmt)
root.addHandler(h)
- level = kwargs.get("level")
+ level = kwargs.pop("level", None)
if level is not None:
root.setLevel(level)
+ if kwargs:
+ keys = ', '.join(kwargs.keys())
+ raise ValueError('Unrecognised argument(s): %s' % keys)
finally:
_releaseLock()