Traceback in Logging

Kottiyath n.kottiyath at gmail.com
Tue Jan 6 14:33:29 CET 2009


Hi all,
   Is it possible to print traceback for all logging?
   I have created something like this:

def trace():
    import traceback
    return ''.join(traceback.format_stack(limit=4)[1:])

And during every logging, append it -
        self.logger.info('Data: %s, kwargs: %s Traceback: %s' %(data,
kwargs, trace()))

-->Result<--

2009-01-06 18:52:21,483 - test- INFO
---> Data:, kwargs: {}
Traceback:   File "C:\test.py", line 48, in success
    super(testObj, self).success(reply, **kwargs)
  File "C:\test.py", line 87, in success
    self.logger.info('Data: %s, kwargs: %s Traceback: %s' %(data,
kwargs, trace()))
  File "C:\test.py", line 151, in trace
    return ''.join(traceback.format_stack(limit=4)[1:])

This seems somewhat kludgy. Is it possible in logging mechanism itself
to provide traceback as default?

I use Python2.4, so LoggingAdapter is not there too.



More information about the Python-list mailing list