logging module: log method with keyword arguments

Discussion in 'Python' started by David Konerding, Sep 10, 2003.

  1. 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
    David Konerding, Sep 10, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Edward Diener
    Replies:
    14
    Views:
    4,941
    Josiah Carlson
    Apr 6, 2004
  2. rh0dium
    Replies:
    2
    Views:
    341
    rh0dium
    Aug 4, 2005
  3. Replies:
    2
    Views:
    441
    Joel Hedlund
    May 11, 2006
  4. Royan
    Replies:
    1
    Views:
    1,445
    Andrea Francia
    Apr 1, 2008
  5. Peter Motzfeldt
    Replies:
    1
    Views:
    148
Loading...

Share This Page