Controlling exception handling of logging module

sj seungwjun at gmail.com
Wed Oct 19 14:33:32 EDT 2005


Suppose the following are part of a long file and executed:

logging.basicConfig(stream = sys.stderr, level=logging.INFO)
logging.info("%d %d", 1, 2, 3)                                # buggy

Python prints the traceback of the error as follows:

Traceback (most recent call last):
  File ".../local/lib/python2.4/logging/__init__.py", line 706, in emit
    msg = self.format(record)
  File ".../local/lib/python2.4/logging/__init__.py", line 592, in
format
    return fmt.format(record)
  File ".../local/lib/python2.4/logging/__init__.py", line 382, in
format
    record.message = record.getMessage()
  File ".../local/lib/python2.4/logging/__init__.py", line 253, in
getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting

It tells why error occurred, but the traceback is not helpful to locate
where it occurred.  I believe that's because the logging module caught
and ate up the exception.  I understand that this is a sensible setting
as logging shouldn't harm the main program, but in the debugging phase,
I really want this exception to propagate up so that I can easily
locate from my code.  Is there any way to control this behavior so the
error is not handled by the logging module itself?




More information about the Python-list mailing list