DragonBobZ
DragonBobZ

Reputation: 2454

Gunicorn Access Logs Shows Empty User

With the below command:

gunicorn --workers=4 my_project.wsgi -b 0.0.0.0:8000 --log-level=info --access-logfile=my_project/logs/gunicorn_logs.txt

I am able to log every request. However, these logs do not include information about the user:

127.0.0.1 - - [02/Aug/2018:13:46:44 -0500] GET /metrics/data HTTP/1.1 200 1589185 http://localhost:8000/ Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36

The default formatting string is %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s", which, if I understand the documentation correctly, the "user name" should show up after the "referrer address" and before the "date of the request". I have also included that format string as part of the run command just to verify that the same thing happens, and it does.

Is it possible for me to have Gunicorn also log the user that made the request? Any help would be appreciated.

This is running Gunicorn 19.7.1 and Django 1.11.9.

Upvotes: 1

Views: 1171

Answers (1)

Håken Lid
Håken Lid

Reputation: 23064

From looking at the gunicorn source code, it seems that this is only for http basic authentication user name. That's not a very common authentication method these days, and django has its own user authentication, which has nothing to do with basic auth.

Unless you are using basic auth (for some reason), the expected value is -. If you want to log the django user for each request, you have to use django's own logging.

Upvotes: 8

Related Questions