python from eliot import start_action, to_file, register_action def divide(a, b): with start_action(action_type="division", a=a, b=b) as action: try: result = a / b action.add_success_fields(result=result) return result except ZeroDivisionError as e: action.add_failure_fields(exception=str(e)) raise if __name__ == '__main__': import eliot eliot.add_destination(eliot.logfile.PeriodicRotatingLogFile("log.txt", rotateLength=1000000)) eliot.start_action(action_type='main') try: result = divide(10, 2) print("Result:", result) except ZeroDivisionError as e: print("Error:", e) eliot.end_action()


上一篇:
下一篇:
切换中文