My Django application, used in mod_wsgi under Apache using Django's standard WSGIHandler, authenticates customers via form login around the Django side. To Apache, the consumer is anonymous. This will make the Apache access log less helpful.

It is possible to method to pass the username back with the WSGI wrapper to Apache after handling the request, to ensure that it seems within the Apache access log?

(Versions: Django 1.1.1, mod_wsgi 2.5, Apache 2.2.9)

You are able to only get it done if using embedded mode and only when you utilize another package known as apswigpy, which supplies a Python binding for original Apache request object. The mod_wsgi package offers an optional mechanism for permitting original Apache request resist be passed as Python CObject reference in WSGI atmosphere. You utilize that along with apswigpy something similar to:

from apache.httpd import request_rec

r = request_rec(environ['apache.request_rec'])

r.user = user

A minimum of I believe which will setup the right information which access logging may then use.

You need to really take this discussion to the mod_wsgi subscriber list.

You could utilize mod_auth_tkt. An auth_tkt is really a signed cookie using the user id that Apache can understand. Your internet application would need to set the cookie once the user logs out and in. Apache can derive a REMOTE_USER in the cookie, pass it for your web application or perhaps a non-Django web application running on a single server, include it in logs, whatever.

This most likely is not what you are expecting, but you could utilize the username inside your URL plan. This way the consumer come in the road portion of your apache logs.

You'd have to modify your authentication to ensure that auth-needed reactions are apparent within the apache logs, otherwise when viewing the logs you might attribute unauthenticated demands to authenticated customers. E.g. return a brief redirect towards the login page when the request is not authenticated.