"" import OS import logging.config import time # Define three logging output formats to start standard_format =" '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' \ '[%(levelname)s][%(message)s]' # GetLogger simple_format = '[%(levelName)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s' Id_simple_format = '[%(levelName)s][%(asctime)s] %(message)s Current_data = time.strftime("%Y-% M -% D "), current_data = time.strftime("%Y-% M -% D "), Logfile_name = logfile_dir + '/' + current_data + '.log') # create a log directory if not os.path.isdir(logfile_dir) Os.mkdir (logfile_dir) = os.path.join(logfile_dir) Logfile_name) # log config dictionary LOGGING_DIC = {'version': 1, 'disable_existing_loggers': False, 'formatters': {'standard': { 'format': standard_format }, 'simple': { 'format': simple_format }, }, 'filters': {}, 'handlers': {# print to terminal log 'console': {'level': 'DEBUG', 'class': 'logging.streamhandler ', # print to screen 'formatter': 'simple'}, # print to file log, collect info and above log 'default': {'level': 'DEBUG', 'class': 'logging. Handlers. RotatingFileHandler', # save to file 'formatter' : 'standard', 'filename' : logfile_path, # 'maxBytes' log files: 1024*1024*5, # log size 5M 'backupCount': 5, 'encoding': 'utf-8', # log file encoding},}, 'loggers': {# logging.getLogger(__name__);} ['default', 'console'], # write the log data to the file and print it to the screen 'level': 'DEBUG', 'propagate': True, # pass up (logger)},}, } logging. Config. DictConfig (LOGGING_DIC) # import defined above logging configuration logger. = logging getLogger (__name__) # # to generate a log examples logger.setLevel(logging.DEBUG) # logger.info('It works! ') # log the status of the file