Log uncaught exceptions
This commit is contained in:
parent
9068f46d40
commit
eff7d0aca9
30
app/log.py
30
app/log.py
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
@ -45,10 +47,23 @@ log.addHandler(stderr)
|
|||||||
log.addHandler(syslog)
|
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):
|
def DEBUG(msg):
|
||||||
log.debug(msg)
|
log.debug(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def EXCEPTION(msg):
|
||||||
|
log.exception(msg)
|
||||||
|
|
||||||
|
|
||||||
def ERROR(msg):
|
def ERROR(msg):
|
||||||
log.error(msg)
|
log.error(msg)
|
||||||
|
|
||||||
@ -61,3 +76,18 @@ if __name__ == "__main__":
|
|||||||
DEBUG("hi debug")
|
DEBUG("hi debug")
|
||||||
ERROR("hi error")
|
ERROR("hi error")
|
||||||
INFO("hi info")
|
INFO("hi info")
|
||||||
|
EXCEPTION("hi exception")
|
||||||
|
|
||||||
|
def f():
|
||||||
|
return g()
|
||||||
|
|
||||||
|
def g():
|
||||||
|
return h()
|
||||||
|
|
||||||
|
def h():
|
||||||
|
return i()
|
||||||
|
|
||||||
|
def i():
|
||||||
|
1 / 0
|
||||||
|
|
||||||
|
f()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user