changeset 2486:6f537e3da9c4 beta

add IP into base logging, and change a little IP extraction login, if some header is passed as empty
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 19 Jun 2012 21:42:14 +0200
parents 133209bf300c
children 995d938ce14b
files rhodecode/lib/base.py
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/base.py	Tue Jun 19 20:27:53 2012 +0200
+++ b/rhodecode/lib/base.py	Tue Jun 19 21:42:14 2012 +0200
@@ -35,9 +35,17 @@
     proxy_key2 = 'HTTP_X_FORWARDED_FOR'
     def_key = 'REMOTE_ADDR'
 
-    return environ.get(proxy_key2,
-                       environ.get(proxy_key, environ.get(def_key, '0.0.0.0'))
-                       )
+    ip = environ.get(proxy_key2)
+    if ip:
+        return ip
+
+    ip = environ.get(proxy_key)
+
+    if ip:
+        return ip
+
+    ip = environ.get(def_key, '0.0.0.0')
+    return ip
 
 
 class BasicAuth(AuthBasicAuthenticator):
@@ -178,12 +186,13 @@
                 self.rhodecode_user.set_authenticated(
                     cookie_store.get('is_authenticated')
                 )
-            log.info('User: %s accessed %s' % (
-                auth_user, safe_unicode(environ.get('PATH_INFO')))
+            log.info('IP: %s User: %s accessed %s' % (
+               self.ip_addr, auth_user, safe_unicode(environ.get('PATH_INFO')))
             )
             return WSGIController.__call__(self, environ, start_response)
         finally:
-            log.info('Request to %s time: %.3fs' % (
+            log.info('IP: %s Request to %s time: %.3fs' % (
+                _get_ip_addr(environ),
                 safe_unicode(environ.get('PATH_INFO')), time.time() - start)
             )
             meta.Session.remove()