python3 logging 日志记录
code
macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % cat test.py import logging logging.basicConfig(level=logging.INFO, filename='mylog.log') logging.info('Starting program') logging.info('Trying to divide 1 by 0') print(1 / 0) macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % python3 test.py Traceback (most recent call last): File "test.py", line 5, in <module> print(1 / 0) ZeroDivisionError: division by zero macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % cat mylog.log INFO:root:Starting program INFO:root:Trying to divide 1 by 0 macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop %