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

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to