源于: 功能类代码 – Logsetclass.py
网上代码1:
# 日志模块
import logging
import traceback
# 引入日志
logging.basicConfig(filename='log_record.txt',
level=logging.DEBUG, filemode='w', format='[%(asctime)s] [%(levelname)s] >>> %(message)s',
datefmt='%Y-%m-%d %I:%M:%S')
try:
print(a+1) # 放主要代码
except Exception as e:
logging.error("Main program error:")
logging.error(e)
logging.error(traceback.format_exc