diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-11-25 15:11:46 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-11-25 15:11:46 (GMT) |
commit | d27e05d7345c80f6bda15187f01887e3be2c49c8 (patch) | |
tree | cd7b1658ee59a4f11309e7647a94613a2ec7e116 /Lib/logging | |
parent | bf6ecf92fa9800b1b99d78a82518bcae30115e0c (diff) | |
download | cpython-d27e05d7345c80f6bda15187f01887e3be2c49c8.zip cpython-d27e05d7345c80f6bda15187f01887e3be2c49c8.tar.gz cpython-d27e05d7345c80f6bda15187f01887e3be2c49c8.tar.bz2 |
Closes #16521: Improved error handling for basicConfig(), added tests for same.
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 4191b22..361fa88 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1674,22 +1674,25 @@ def basicConfig(**kwargs): _acquireLock() try: if len(root.handlers) == 0: - filename = kwargs.get("filename") + filename = kwargs.pop("filename", None) if filename: - mode = kwargs.get("filemode", 'a') + mode = kwargs.pop("filemode", 'a') hdlr = FileHandler(filename, mode) else: - stream = kwargs.get("stream") + stream = kwargs.pop("stream", None) hdlr = StreamHandler(stream) - fs = kwargs.get("format", BASIC_FORMAT) - dfs = kwargs.get("datefmt", None) - style = kwargs.get("style", '%') + fs = kwargs.pop("format", BASIC_FORMAT) + dfs = kwargs.pop("datefmt", None) + style = kwargs.pop("style", '%') fmt = Formatter(fs, dfs, style) hdlr.setFormatter(fmt) root.addHandler(hdlr) - level = kwargs.get("level") + level = kwargs.pop("level", None) if level is not None: root.setLevel(level) + if kwargs: + s = ', '.join(kwargs.keys()) + raise ValueError('Unexpected in keyword arguments: %s' % s) finally: _releaseLock() |