Issue 18413: logging.error('asdf', extra={'msg':123}) raise KeyError exception (original) (raw)

Hello. I noticed strange behavior of logging module, when debugging my code:

$ python Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import logging logging.error('asdf') ERROR:root:asdf logging.error('asdf', extra={'msg':123}) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/logging/init.py", line 1575, in error root.error(msg, *args, **kwargs) File "/usr/lib/python2.7/logging/init.py", line 1166, in error self._log(ERROR, msg, args, **kwargs) File "/usr/lib/python2.7/logging/init.py", line 1257, in _log record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra) File "/usr/lib/python2.7/logging/init.py", line 1235, in makeRecord raise KeyError("Attempt to overwrite %r in LogRecord" % key) KeyError: "Attempt to overwrite 'msg' in LogRecord"

Originally code was extra=locals() and 'msg' was local variable, but it doesn't matter.