Django应该登录gunicorn的日志文件

时间:2014-10-16 05:42:26

标签: python django logging gunicorn

我有一台在服务器上运行的django-app。它始于gunicorn。我希望django将它的日志输出放入gunicorn的日志文件中。但是当我查看文件时,没有django-log-entry。

我想当我在控制台上打印日志时,gunicorn会记录它。

以下是gunicorn开头的代码片段:

exec ../bin/gunicorn ${django_app_name}.wsgi:application \
        -D \
        -p $unicorn_pidfile \
        -b unix:$unicorn_sockfile \
        --log-level debug \
        --log-file $unicorn_logfile \
        --error-logfile $unicorn_error_logfile \
       # --log-level debug \
       # --log-level debug --log-file $unicorn_logfile \
        #--log-level error --log-file $unicorn_error_logfile \
         -w $num_workers \
        --name $django_app_name > $unicorn_logfile

以下是我(尝试)登录django(settings.py)的方式:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': "[ThreadID: %(thread)d %(asctime)s.%(msecs)d] %(levelname)s: %(message)s",
            'datefmt': "%H:%M:%S"
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'propagate': True,
            'level': 'DEBUG',
        },
        'rest': {
            'handlers': ['console'],
            'level': 'DEBUG',
        },
    }
}

1 个答案:

答案 0 :(得分:0)

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mCategory = getArguments().getString(ARG_CATEGORY);
        }
    }

只需删除脚本末尾的exec ../bin/gunicorn ${django_app_name}.wsgi:application \ -D \ -p $unicorn_pidfile \ -b unix:$unicorn_sockfile \ --log-level debug \ --log-file $unicorn_logfile \ --error-logfile $unicorn_error_logfile \ # --log-level debug \ # --log-level debug --log-file $unicorn_logfile \ #--log-level error --log-file $unicorn_error_logfile \ -w $num_workers \ --name $django_app_name 即可。 > $unicorn_logfile足以记录日志。但是您要通过--log-file $unicorn_logfile运算符

覆盖现有日志