python logging
import logging import os import datetime if __name__ == '__main__': level = logging.INFO log_filename = "D:/log/log_%s.log" try: if not os.path.exists(log_filename % datetime.datetime.now().strftime('%Y-%m-%d')): if not os.path.exists("D:/log/log_%%s.log"): os.makedirs("D:/log/log_%%s.log") f = open(log_filename, 'ab+') f.close() except FileExistsError as ex: print(ex) log_handler = logging.FileHandler(log_filename, encoding='UTF-8') console = logging.StreamHandler() logging.basicConfig( level=level, format='%(asctime)s %(levelname)s %(thread)d --- [%(threadName)s] %(filename)s-%(lineno)d : %(message)s',handlers=[log_handler,console]) logging.getLogger("requests").setLevel(logging.WARNING) logging.info("开始定时任务{0}".format(datetime.datetime.now()))