logging module: log method with keyword arguments

David Konerding dek at compbio.berkeley.edu
Tue Sep 9 19:40:12 EDT 2003


Hi,
I am trying to write my own Logging Handler object, to work within an existing logging system that I use.

However, when I try to dispatch log calls to the logger, I get an error in an internal logging call.

Here's an example code:
logger = logging.getLogger('test')
logger_handler = logging.StreamHandler(sys.stdout)
logger_formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
logger_handler.setFormatter(logger_formatter)
logger.addHandler(logger_handler)
logger.setLevel(logging.DEBUG)
logger.debug("Message: %(msg2)", msg2="foo")

The message I get is:

  File "/home/portnoy/d5/dek/sw/rh9/Python-2.3/lib/python2.3/logging/__init__.py", line 879, in debug
    apply(self._log, (DEBUG, msg, args), kwargs)
TypeError: _log() got an unexpected keyword argument 'msg2'

Now, I can kind of understand this because the documentation for the debug() method says:

The only keyword argument in kwargs which is inspected is exc_info which,
if it does not evaluate as false, causes exception information (via a
call to sys.exc_info()) to be added to the logging message.

My only problem is that the documentation doesn't say anything about
not accepting kwargs which aren't "exc_info" (I recognize the syntax I used above doesn't
actually do what I wanted anyway).

Dave




More information about the Python-list mailing list