Django日志配置
发布时间:2020-12-20 10:24:33 所属栏目:Python 来源:网络整理
导读:BASE_LOG_DIR = os.path.join(BASE_DIR,"log")LOGGING = { 'version': 1,'disable_existing_loggers': False,'formatters': { 'standard': { 'format': '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' '[%(levelna
BASE_LOG_DIR = os.path.join(BASE_DIR,"log") LOGGING = { 'version': 1,'disable_existing_loggers': False,'formatters': { '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' },'collect': { 'format': '%(message)s' } },'filters': { 'require_debug_true': { '()': 'django.utils.log.RequireDebugTrue',},'handlers': { 'console': { 'level': 'DEBUG','filters': ['require_debug_true'],# 只有在Django debug为True时才在屏幕打印日志 'class': 'logging.StreamHandler','formatter': 'simple' },'SF': { 'level': 'INFO','class': 'logging.handlers.RotatingFileHandler',# 保存到文件,根据文件大小自动切 'filename': os.path.join(BASE_LOG_DIR,"xxx_info.log"),# 日志文件 'maxBytes': 1024 * 1024 * 50,# 日志大小 50M 'backupCount': 3,# 备份数为3 xx.log --> xx.log.1 --> xx.log.2 --> xx.log.3 'formatter': 'standard','encoding': 'utf-8','TF': { 'level': 'INFO','class': 'logging.handlers.TimedRotatingFileHandler',# 保存到文件,根据时间自动切 'filename': os.path.join(BASE_LOG_DIR,# 日志文件 'backupCount': 3,# 备份数为3 xx.log --> xx.log.2018-08-23_00-00-00 --> xx.log.2018-08-24_00-00-00 --> ... 'when': 'D',# 每天一切, 可选值有S/秒 M/分 H/小时 D/天 W0-W6/周(0=周一) midnight/如果没指定时间就默认在午夜 'formatter': 'standard','error': { 'level': 'ERROR',# 保存到文件,自动切 'filename': os.path.join(BASE_LOG_DIR,"xxx_err.log"),# 日志文件 'maxBytes': 1024 * 1024 * 5,# 日志大小 50M 'backupCount': 5,'formatter': 'standard','collect': { 'level': 'INFO',"xxx_collect.log"),'maxBytes': 1024 * 1024 * 50,'formatter': 'collect','encoding': "utf-8" } },'loggers': { '': { # 默认的logger应用如下配置 'handlers': ['SF','console','error'],# 上线之后可以把'console'移除 'level': 'DEBUG','propagate': True,'collect': { # 名为 'collect'的logger还单独处理 'handlers': ['console','collect'],'level': 'INFO',} },} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |