# HG changeset patch # User Marcin Kuzminski # Date 2012-06-19 19:42:14 # 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 --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -35,9 +35,17 @@ def _get_ip_addr(environ): 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 @@ class BaseController(WSGIController): 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()