lofidevops
lofidevops

Reputation: 16962

Where are stack traces for my Django / uWSGI vassal logged?

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 the only logs I get are things like this:

[pid: 2887|app: 0|req: 7/7] 1.2.3.4 () {52 vars in 936 bytes} [Fri Oct 13 20:46:04 2017] POST /mysite/login/ => generated 27 bytes in 2453 msecs (HTTP/1.1 500) 4 headers in 126 bytes (2 switches on core 0)
[pid: 2887|app: 0|req: 8/8] 1.2.3.4 () {44 vars in 702 bytes} [Fri Oct 13 20:52:24 2017] GET / => generated 1561 bytes in 2 msecs (HTTP/1.1 200) 4 headers in 124 bytes (2 switches on core 0)

Where's the stack trace for the 500 error? (Is there a module I need to enable?)

Upvotes: 6

Views: 3873

Answers (1)

lofidevops
lofidevops

Reputation: 16962

The problem is that Django is not sending the logs anywhere. You need to:

Any stack traces that would normally show up in your console will now appear in your UWSGI logfile.

For example:

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

For other logging options (filters, formatting...) see https://docs.djangoproject.com/en/1.11/topics/logging/#configuring-logging (thanks to solarissmoke for the link).

Upvotes: 11

Related Questions