logging module: log method with keyword arguments

D

David Konerding

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top