gunicorn配置文件为gunicorn_config.py里面有日志的配置
# errorlog = '/home/admin/output/erebus/logs/gunicorn_error.log'
# loglevel = 'info'
# loglevel = 'debug'
# accesslog = '/home/admin/output/erebus/logs/gunicorn_access.log'
# access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
django如何捕获gunicorn的日志
注释掉上面的配置,则相关日志不输出,然后在django日志配置里添加
logconfig_dict = {
'version':1,
'disable_existing_loggers': False,
'loggers':{
"gunicorn.error": {
"level": "DEBUG",# 打日志的等级可以换的,下面的同理
"handlers": ["error_file"], # 对应下面的键
"propagate": 1,
"qualname": "gunicorn.error"
},
"gunicorn.access": {
"level": "DEBUG",
"handlers": ["access_file"],
"propagate": 0,
"qualname": "gunicorn.access"
}
},
'handlers':{
"error_file": {
"class": "logging.handlers.RotatingFileHandler",
"maxBytes": 1024*1024*1024,# 打日志的大小,我这种写法是1个G
"backupCount": 1,# 备份多少份,经过测试,最少也要写1,不然控制不住大小
"formatter": "generic",# 对应下面的键
# 'mode': 'w+',
"filename": "/你要放日志的路径/gunicorn.error.log"# 打日志的路径
},
"access_file": {
"class": "logging.handlers.RotatingFileHandler",
"maxBytes": 1024*1024*1024,
"backupCount": 1,
"formatter": "generic",
"filename": "/你要放日志的路径/gunicorn.access.log",
}
},
'formatters':{
"generic": {
"format": "'[%(process)d] [%(asctime)s] %(levelname)s [%(filename)s:%(lineno)s] %(message)s'", # 打日志的格式
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",# 时间显示方法
"class": "logging.Formatter"
},
"access": {
"format": "'[%(process)d] [%(asctime)s] %(levelname)s [%(filename)s:%(lineno)s] %(message)s'",
"class": "logging.Formatter"
}
}
}