Parand Parand - 4 months ago 12
Apache Configuration Question

Injecting app level username/userid into nginx/Apache log

Is there a way to inject an application level username or id (in this case, the django username or id) into the Apache or ngnix log? Note that I'm not asking about the HTTP auth username.


We do something like this, only we tell Apache to store the the Django sessionid cookie.

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %{sessionid}C" withsession
CustomLog logs/ withsession

It's sort of a two-step process to map the sessionid to the user, but it's easy to implement. You could do something similar by setting a cookie with the explicit ID in it and then using the custom log to capture it.