[ZODB-Dev] Re: Weird errors with Zope 2.7.7
Tim Peters
tim at zope.com
Tue Oct 25 12:23:38 EDT 2005
[Chris Withers]
> I'd like to be able to do:
>
> logger.info('blah',show_stack=True)
Well, you can't ;-)
It's not hard to roll yourself, so I expect (but don't know) that the
logging module's author would resist adding it. For example,
import traceback
from cStringIO import StringIO
...
... some class ...
... in some method ...
f = StringIO()
traceback.print_stack(file=f)
logging.info("blah\nStack trace:\n%s" % f.getvalue())
If you want to do that more than once, a utility function could help:
def capture_stack():
f = StringIO()
traceback.print_stack(sys._getframe(1), file=f)
return "\nStack trace:\n" + f.getvalue()
and then in the method:
logging.info("blah" + capture_stack())
Using the utility function also keeps the call to traceback.print_stack()
out of the stack trace (that's the purpose of "sys._getframe(1)").
More information about the ZODB-Dev
mailing list