1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
   |  import logging import logging.config
  standard_format = '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' \                   '[%(levelname)s][%(message)s]' 
  simple_format = '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
  logfile_path = 'a3.log'
  LOGGING_DIC = {     'version': 1,     'disable_existing_loggers': False,     'formatters': {         'standard': {             'format': standard_format         },         'simple': {             'format': simple_format         },     },     'filters': {},       'handlers': {                  'console': {             'level': 'DEBUG',             'class': 'logging.StreamHandler',               'formatter': 'simple'         },                  'default': {             'level': 'DEBUG',             'class': 'logging.handlers.RotatingFileHandler',               'formatter': 'standard',             'filename': logfile_path,               'maxBytes': 1024*1024*5,               'backupCount': 5,             'encoding': 'utf-8',           },     },     'loggers': {                  '': {             'handlers': ['default', 'console'],               'level': 'DEBUG',             'propagate': True,           },       }, }
 
 
  logging.config.dictConfig(LOGGING_DIC)   logger1 = logging.getLogger('xxx') logger1.debug('测试')
 
  |