Python logging stack_info demo script - Pastebin.com (original) (raw)

Guest User

a guest

Nov 14th, 2010

422

0

Never

Not a member of Pastebin yet? Sign Up, it unlocks many cool features!

  1. import logging
  2. import sys
  3. import traceback
  4. def func3():
  5. 1 / 0
  6. def func2():
  7. try:
  8. func3()
  9. except Exception:
  10. logging.exception('Error calling func3', stack_info=True)
  11. #f = sys._getframe(1)
  12. #print('Stack (most recent call last):')
  13. #traceback.print_stack(f)
  14. def func1():
  15. logging.debug('How did we get here?', stack_info=True)
  16. func2()
  17. logging.debug('Not sure how we got here!')
  18. def main():
  19. func1()
  20. if __name__ == '__main__':
  21. logging.basicConfig(level=logging.DEBUG, format='%(message)s')
  22. main()