def set_cli_except_hook():
def recommend(possible_solutions):
logger.info('Possible solutions:')
for solution in possible_solutions:
logger.info(' - {0}'.format(solution))
def new_excepthook(tpe, value, trace):
if env.logging.is_high_verbose_level():
# log error including traceback
logger.error(get_exception_as_string(tpe, value, trace))
else:
# write the full error to the log file
with open(env.logging.log_file, 'a') as log_file:
traceback.print_exception(
etype=tpe,
value=value,
tb=trace,
file=log_file)
# print only the error message
print value
if hasattr(value, 'possible_solutions'):
recommend(getattr(value, 'possible_solutions'))
sys.excepthook = new_excepthook
评论列表
文章目录