Advertisement
Guest User

Python logging stack_info demo script

a guest
Nov 14th, 2010
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. import logging
  2. import sys
  3. import traceback
  4.  
  5. def func3():
  6.     1 / 0
  7.  
  8. def func2():
  9.     try:
  10.         func3()
  11.     except Exception:
  12.         logging.exception('Error calling func3', stack_info=True)
  13.         #f = sys._getframe(1)
  14.         #print('Stack (most recent call last):')
  15.         #traceback.print_stack(f)
  16.  
  17. def func1():
  18.     logging.debug('How did we get here?', stack_info=True)
  19.     func2()
  20.     logging.debug('Not sure how we got here!')
  21.  
  22. def main():
  23.     func1()
  24.  
  25. if __name__ == '__main__':
  26.     logging.basicConfig(level=logging.DEBUG, format='%(message)s')
  27.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement