Which Django/Python handler class will pass logs to the UWSGI logger?

回眸只為那壹抹淺笑 提交于 2019-12-23 18:04:12

问题


I am running my Django site as a vassal of UWSGI emperor. I have created /etc/uwsgi-emperor/vassals/mysite.ini as follows:

[uwsgi]
socket = /var/opt/mysite/uwsgi.sock
chmod-socket = 775
chdir = /opt/mysite
master = true
virtualenv = /opt/mysite_virtualenv
env = DJANGO_SETTINGS_MODULE=mysite.settings
module = mysite.wsgi:application
uid = www-data
gid = www-data
processes = 1
threads = 1
plugins = python3,logfile
logger = file:/var/log/uwsgi/app/mysite.log
vacuum = true

But Django logs are not appearing in file:/var/log/uwsgi/app/mysite.log. Which handler class will pass the logs on to UWSGI?


回答1:


You can use the logging.StreamHandler class. For example, defining LOGGING in settings.py as follows:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'filters': None,
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'level': 'DEBUG',
        },
    },
}


来源:https://stackoverflow.com/questions/46747036/which-django-python-handler-class-will-pass-logs-to-the-uwsgi-logger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!