some django's logs are missing when host in uwsgi with multiple process

∥☆過路亽.° 提交于 2019-12-05 05:40:42

This is because it is not safe to write to the same file from several workers. You should write logs to different files from each worker, or try to use SysLogHandler

http://docs.python.org/library/logging.handlers.html

/etc/rsyslog.d/local-myapp.conf:

local0.*                         -/var/log/myapp/app.log

settings.py:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'user': {
            '()': 'core.log.UserFilter',
        }
    },
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(user)s %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(asctime)s %(module)s %(user)s %(message)s'
        },
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'filters': ['user'],
        },
        'syslog':{
            'level': 'INFO',
            'class': 'logging.handlers.SysLogHandler',
            'formatter': 'verbose',
            'filters': ['user'],
            'facility': 'local0',
            'address': '/dev/log',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    },
    'root': {
        'handlers': ['syslog'],
        'level': 'INFO',
    }
}

You also can try to write log messages into console and let uwsgi write the logs by himself.

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