Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module C:
- import A
- from B import T
- logger = logging.getLogger(__name__)
- # configure all loggers to sys.stdout
- fileConfig("path-to-config", disable_existing_loggers=False)
- def somefunc():
- # ... code that does stuff with A and logs a bunch from A's logger
- raise Exception
- t = T(somefunc)
- t.run()
- Module A:
- logger = logging.getLogger(__name__)
- # ... helper functions that use logger
- Module B:
- stream = StringIO()
- logger = logging.getLogger(__name__)
- # ... code to format logger and add stream as handler
- class T():
- def run(func):
- try:
- result = func(*args, **kwargs)
- except:
- send_email(stream.getvalue())
- class T():
- def run(func):
- try:
- sys.stdout = stream
- result = func(*args, **kwargs)
- except:
- send_email(stream.getvalue())
- finally:
- sys.stdout = sys.__stdout__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement