Skip to content

Instantly share code, notes, and snippets.

@IlianIliev
Created February 22, 2019 16:02
Show Gist options
  • Save IlianIliev/710d0eab809f5b328af163ee9fe8a1f7 to your computer and use it in GitHub Desktop.
Save IlianIliev/710d0eab809f5b328af163ee9fe8a1f7 to your computer and use it in GitHub Desktop.
import logging
import sys
logging.basicConfig(filename='mybot.log', level=logging.DEBUG,
format='%(asctime)s: %(name)s: %(levelname)s: %(message)s')
logger = logging.getLogger(__name__)
logger.info('Start')
def log_uncaught_exception(exctype, value, traceback):
logger.error('Unhandled Exception caught', exc_info=(exctype, value, traceback))
sys.excepthook = log_uncaught_exception
try:
1/0
except:
logger.error('ERrrrrrrorrr')
logger.info('End')
1/0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment