Created
October 10, 2017 13:38
-
-
Save cliffxuan/a4979d927126f5572b3a2306c6a652f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from contextlib import ContextDecorator | |
format = '%(asctime)s - %(levelname)s - %(message)s' | |
ch = logging.StreamHandler() | |
ch.setFormatter(logging.Formatter(format)) | |
logger = logging.getLogger() | |
logger.setLevel(logging.DEBUG) | |
logger.addHandler(ch) | |
class context_decorator(ContextDecorator): | |
def __enter__(self): | |
return self | |
def __exit__(self, *exc): | |
if exc != (None, None, None): | |
logging.info("***********************start") | |
logging.exception("Uncaught exception: %s", exc[1]) | |
logging.info("***********************end") | |
return False | |
with context_decorator(): | |
1 / 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment