python - How to debug a script using the module logging -
i have script using several imported submodules of mine, each of them using module logging. in 1 of them wrote bad code line, can figure out is. indeed, synthax typical logging output argument var is:
logging.info("my var=%s", var)
if number of arguments not correspond number of %s in string, there error message logging follows :
traceback (most recent call last): file "/usr/lib/python2.6/logging/__init__.py", line 776, in emit msg = self.format(record) file "/usr/lib/python2.6/logging/__init__.py", line 654, 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 valueerror: incomplete format
the problem error message generic: not show name of module probleme appear, nor code line, nor arguments... makes impossible me find out wrote bad call logging.info()
q&d braindead solution : edit /usr/lib/python2.6/logging/init.py , wrap line 776 in try/except clause:
try: msg = self.format(record) except valueerror: import pdb; pdb.set_trace()
then re-run code shell , whatever needed re-raise exception. you'll sent in step debugger, can inspect whole call stack.
once problem solved, rollback edits. , contribute patch logging
module emits more useful error message...
oh , btw : automated tests way catch kind of errors possible, when remember part of code touched.
Comments
Post a Comment