import sys
import traceback

def logexception(type, value, tb):
    print(traceback.format_exception(type, value, tb))
sys.excepthook = logexception
Convert Python exception information to string for logging