# HG changeset patch # User Marcin Kuzminski # Date 1340134934 -7200 # Node ID 6f537e3da9c4707d807fcee70ee2869aa50f7b03 # Parent 133209bf300c9ddb29cd5df04260da9596c775ad add IP into base logging, and change a little IP extraction login, if some header is passed as empty diff -r 133209bf300c -r 6f537e3da9c4 rhodecode/lib/base.py --- 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()