标签:lin base file __file__ Matter odi pre ble level
import os
# 日志相关的配置
BASE_DIR=os.path.dirname(os.path.dirname(__file__))
standard_format = ‘%(asctime)s - task:%(name)s - %(filename)s:%(lineno)d -‘ \
‘ %(levelname)s : [%(message)s]‘
simple_format = ‘%(filename)s:%(lineno)d - %(levelname)s : [%(message)s]‘
fh1_path = os.path.join(BASE_DIR,‘log‘,‘a1.log‘)
fh2_path = os.path.join(BASE_DIR,‘log‘,‘a2.log‘)
# log配置字典
LOGGING_DIC = {
‘version‘: 1,
‘disable_existing_loggers‘: False,
‘formatters‘: {
‘standard‘: {
‘format‘: standard_format
},
‘simple‘: {
‘format‘: simple_format
},
},
‘filters‘: {},
‘handlers‘: {
#打印到终端的日志
‘ch‘: {
‘level‘: ‘DEBUG‘,
‘class‘: ‘logging.StreamHandler‘, # 打印到终端
‘formatter‘: ‘simple‘
},
#打印到a1.log文件的日志
‘fh1‘: {
‘level‘: ‘DEBUG‘,
‘class‘: ‘logging.FileHandler‘, # 保存到文件
‘formatter‘: ‘standard‘,
‘filename‘: fh1_path, # 日志文件的路径
‘encoding‘: ‘utf-8‘, # 日志文件的编码,再也不用担心中文log乱码了
},
# 打印到a2.log文件的日志
‘fh2‘: {
‘level‘: ‘DEBUG‘,
‘class‘: ‘logging.FileHandler‘, # 保存到文件
‘formatter‘: ‘simple‘,
‘filename‘: fh2_path, # 日志文件的路径
‘encoding‘: ‘utf-8‘, # 日志文件的编码,再也不用担心中文log乱码了
},
},
‘loggers‘: {
‘‘: {
‘handlers‘: [‘fh1‘, ‘fh2‘, ‘ch‘],
‘level‘: ‘DEBUG‘,
},
},
}
标签:lin base file __file__ Matter odi pre ble level
原文地址:https://www.cnblogs.com/fushaunglin/p/9461744.html