LOG的動態傳參
阿新 • • 發佈:2019-01-12
import logging
import logging.config
def LOGGING_START():
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'
id_simple_format = '[%(asctime)s] %(message)s'時間,資訊
LOGGING_DIC = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': standard_format
},
'simple': {
'format': simple_format
},
'id_simple_format': {
'format': id_simple_format
},
},
'filters': {},
'handlers': {
'scream': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'staff_file': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'id_simple_format',
'filename': settings.LOGGING + src.username,動態
'maxBytes': 9000,大小
'backupCount': 5,迭代5次
'encoding': 'utf-8',
},
},
'loggers': {
'': {
'handlers': ['staff_file'],#可以加輸出到螢幕的東西
'level': 'DEBUG',
'propagate': True,
},
},
}
logging.config.dictConfig(LOGGING_DIC)
logger = logging.getLogger('')
return logger