From e080be82fb10fbd39a942a0e53afead620cac712 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 15 Mar 2013 13:57:58 -0400 Subject: [PATCH] Add the user's client string to our Django logs. This should let us distinguish e.g. mobile from API bots. (imported from commit 192114a0f79bfa7fb918e8c026da63ef772c2449) --- zephyr/middleware.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/zephyr/middleware.py b/zephyr/middleware.py index 7ec2e3d5c7..53050f1ad4 100644 --- a/zephyr/middleware.py +++ b/zephyr/middleware.py @@ -28,16 +28,20 @@ class LogRequests(object): # Get the amount of time spent doing database queries query_time = sum(float(query.get('time', 0)) for query in connection.queries) - # Get the requestor's email address, if available. + # Get the requestor's email address and client, if available. try: email = request._email except Exception: email = "unauth" + try: + client = request._client.name + except Exception: + client = "?" - logger.info('%-15s %-7s %3d %.3fs (db: %.3fs/%sq) %s (%s)' + logger.info('%-15s %-7s %3d %.3fs (db: %.3fs/%sq) %s (%s via %s)' % (remote_ip, request.method, response.status_code, time_delta, query_time, len(connection.queries), - request.get_full_path(), email)) + request.get_full_path(), email, client)) # Log some additional data whenever we return certain 40x errors if 400 <= response.status_code < 500 and response.status_code not in [401, 404, 405]: