def log_exception(exc_type, exc_obj, exc_tb):
    """Log an exception. Can be used as replacement for sys.excepthook."""
    import traceback, logging
    exc_info = traceback.format_exception(exc_type, exc_obj, exc_tb)
    for l in exc_info:
        logging.error(l.strip())
