loggingToFile
import os import logging import time log_dir_name = "logs" log_file_name = 'logger-' + time.strftime('%Y-%m-%d', time.localtime(time.time())) + '.log' log_file = os.path.join(log_dir_name, log_file_name) # if not os.path.exists(log_file): # os.makedirs(log_file) handler = logging.FileHandler(log_file, encoding='UTF-8') logging.basicConfig(level=logging.INFO, filename=log_file, # 由配置参自行创建 否则报错 format='%(asctime)s-%(filename)s[line:%(lineno)d]-%(levelname)s:%(message)s', datefmt='%Y-%m-%d %H:%M:%S') logging.warning("log test!")