Do you know any simple way to find a log call that calls "not enough argumenst for format string". On my workstation, I changed logging/__init__.py to print msg so that I can easily find the line in the source.
But do you know what to do in a test environment where you cannot change the standard python library and run pdb easily?
Note. Tracing is pointless, and it is stored in the registration library. Here is the trace:
File "/usr/lib/python2.6/logging/handlers.py", line 71, in emit if self.shouldRollover(record): File "/usr/lib/python2.6/logging/handlers.py", line 144, in shouldRollover msg = "%s\n" % self.format(record) File "/usr/lib/python2.6/logging/__init__.py", line 648, in format return fmt.format(record) File "/usr/lib/python2.6/logging/__init__.py", line 436, in format record.message = record.getMessage() File "/usr/lib/python2.6/logging/__init__.py", line 306, in getMessage msg = msg % self.args TypeError: not enough arguments for format string
And here is the code in the standard library that catches the error
try: if self.shouldRollover(record): self.doRollover() logging.FileHandler.emit(self, record) except (KeyboardInterrupt, SystemExit): raise except: self.handleError(record)
Solution suggested by Alex: I wrapped getMessage to print msg and args. Here is the code:
def print_log_record_on_error(func): def wrap(self, *args, **kwargs): try: return func(self, *args, **kwargs) except: import sys print >>sys.stderr, "Unable to create log message msg=%r, args=%r " % ( getattr(self, 'msg', '?'), getattr(self, 'args', '?')) raise return wrap import logging logging.LogRecord.getMessage = print_log_record_on_error(logging.LogRecord.getMessage)
python debugging
Piotr czapla
source share