[issue23207] logging.basicConfig does not validate keyword arguments

Jeremy Goss report at bugs.python.org
Wed Mar 18 04:29:29 CET 2015


Jeremy Goss added the comment:

The argument validation in basicConfig has introduced another problem.
I cannot pass in an optional filename/filemode argument pair.

Previously, I passed in an optional logfile argument from ArgumentParser (which could be None). Now, I get a ValueError because filemode is not popped if filename is None.

logging.basicConfig(..., filename=args.logfile, filemode="w")
...
ValueError: Unrecognised argument(s): filemode

Suggested fix to place mode assignment alongside filename in basicConfig():
    filename = kwargs.pop("filename", None)
    mode = kwargs.pop("filemode", 'a')
    if filename:
        h = FileHandler(filename, mode)

----------
nosy: +Jeremy Goss

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23207>
_______________________________________


More information about the Python-bugs-list mailing list