Log uncaught exceptions

This commit is contained in:
Keith Edmunds 2021-04-08 18:31:30 +01:00
parent 9068f46d40
commit eff7d0aca9

View File

@ -2,6 +2,8 @@
import logging
import logging.handlers
import sys
import traceback
from config import Config
@ -45,10 +47,23 @@ log.addHandler(stderr)
log.addHandler(syslog)
def log_uncaught_exceptions(ex_cls, ex, tb):
logging.critical(''.join(traceback.format_tb(tb)))
logging.critical('{0}: {1}'.format(ex_cls, ex))
sys.excepthook = log_uncaught_exceptions
def DEBUG(msg):
log.debug(msg)
def EXCEPTION(msg):
log.exception(msg)
def ERROR(msg):
log.error(msg)
@ -61,3 +76,18 @@ if __name__ == "__main__":
DEBUG("hi debug")
ERROR("hi error")
INFO("hi info")
EXCEPTION("hi exception")
def f():
return g()
def g():
return h()
def h():
return i()
def i():
1 / 0
f()