Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. Module C:
  2. import A
  3. from B import T
  4.  
  5. logger = logging.getLogger(__name__)
  6. # configure all loggers to sys.stdout
  7. fileConfig("path-to-config", disable_existing_loggers=False)
  8.  
  9. def somefunc():
  10. # ... code that does stuff with A and logs a bunch from A's logger
  11. raise Exception
  12.  
  13. t = T(somefunc)
  14. t.run()
  15.  
  16.  
  17. Module A:
  18. logger = logging.getLogger(__name__)
  19. # ... helper functions that use logger
  20.  
  21.  
  22. Module B:
  23. stream = StringIO()
  24. logger = logging.getLogger(__name__)
  25.  
  26. # ... code to format logger and add stream as handler
  27.  
  28. class T():
  29. def run(func):
  30. try:
  31. result = func(*args, **kwargs)
  32. except:
  33. send_email(stream.getvalue())
  34.  
  35. class T():
  36. def run(func):
  37. try:
  38. sys.stdout = stream
  39. result = func(*args, **kwargs)
  40. except:
  41. send_email(stream.getvalue())
  42. finally:
  43. sys.stdout = sys.__stdout__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement