gpt4 book ai didi

logging - 无法获取用于gunicorn 的访问日志

转载 作者:行者123 更新时间:2023-12-02 09:18:21 30 4
gpt4 key购买 nike

我在 ngninx 后面运行 Gunicorn。我想将gunicorn中的错误记录到gunicorn-error.log,并将访问日志记录到gunicorn-access.log。

我的错误日志有效,但访问日志无效,我做错了什么?

这是我的gunicorn.conf.py:

bind = '127.0.0.1:8888'
backlog = 2048
workers = 3
errorlog = '/home/my/logs/gunicorn-error.log'
accesslog = '/home/my/logs/gunicorn-access.log'
loglevel = 'debug'
proc_name = 'gunicorn-my'
pidfile = '/var/run/my.pid'

这是运行gunicorn的脚本:

#!/bin/bash
set -e
ENV=/home/my/env/bin/activate
GUNICORN=gunicorn_django
SETTINGS_PATH=/home/my/app/app/settings
PROJECT_PATH=/home/my/app
CONFROOT=/home/my/app/conf/gunicorn.conf.py

cd $SETTINGS_PATH
source $ENV
export PYTHONPATH=$PROJECT_PATH
exec $GUNICORN app.settings.staging -c $CONFROOT

它创建了gunicorn-error.log和gunicorn-access.log,但只有gunicorn-error.log获取任何日志,例如:

2012-11-20 11:49:57 [27817] [INFO] Starting gunicorn 0.14.6
2012-11-20 11:49:57 [27817] [DEBUG] Arbiter booted
2012-11-20 11:49:57 [27817] [INFO] Listening at: http://127.0.0.1:8888 (27817)
2012-11-20 11:49:57 [27817] [INFO] Using worker: sync
2012-11-20 11:49:58 [27825] [INFO] Booting worker with pid: 27825
2012-11-20 11:49:58 [27828] [INFO] Booting worker with pid: 27828
2012-11-20 11:49:58 [27830] [INFO] Booting worker with pid: 27830

我做错了什么?有人想分享他们的工作gunicorn.conf.py以及错误日志和访问日志吗?

最佳答案

我已将 Django 中的日志配置更改为以下内容,它有所帮助:

LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'generic': {
'format': '%(asctime)s [%(process)d] [%(levelname)s] %(message)s',
'datefmt': '%Y-%m-%d %H:%M:%S',
'()': 'logging.Formatter',
},
},
'handlers': {
'sentry': {
'level': 'ERROR',
'class': 'raven.contrib.django.handlers.SentryHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
'error_file': {
'class': 'logging.FileHandler',
'formatter': 'generic',
'filename': '/home/fungine/gunicorn.error.log',
},
'access_file': {
'class': 'logging.FileHandler',
'formatter': 'generic',
'filename': '/home/fungine/gunicorn.access.log',
},
},
'loggers': {
'django.db.backends': {
'level': 'ERROR',
'handlers': ['console'],
'propagate': False,
},
'raven': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'sentry.errors': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': False,
},
'gunicorn.error': {
'level': 'INFO',
'handlers': ['error_file'],
'propagate': True,
},
'gunicorn.access': {
'level': 'INFO',
'handlers': ['access_file'],
'propagate': False,
},
},
}

关于logging - 无法获取用于gunicorn 的访问日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13472842/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com