[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()
       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)").

For more information about ZODB, see the ZODB Wiki:

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to