From 7f57a86408724315bae539f1b9079d720bdb50f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sat, 24 May 2014 13:48:39 +0200 Subject: [PATCH] Reduce logging of reverse proxy IP lookup and use configured logger Instead of logging the notice that django.axes looks for a HTTP header set by a reverse proxy on each attempt, just log it one-time on first module import. Also use the configured logger (by default axes.watch_login) for the message to be more consistent in logging. --- axes/decorators.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/axes/decorators.py b/axes/decorators.py index f876452..6c037ff 100644 --- a/axes/decorators.py +++ b/axes/decorators.py @@ -64,11 +64,20 @@ ERROR_MESSAGE = ugettext_lazy("Please enter a correct username and password. " "Note that both fields are case-sensitive.") +log = logging.getLogger(LOGGER) +if VERBOSE: + log.info('AXES: BEGIN LOG') + log.info('Using django-axes ' + axes.get_version()) + + +if BEHIND_REVERSE_PROXY: + log.debug('Axes is configured to be behind reverse proxy...looking for header value %s', REVERSE_PROXY_HEADER) + + def get_ip(request): if not BEHIND_REVERSE_PROXY: ip = request.META.get('REMOTE_ADDR', '') else: - logging.debug('Axes is configured to be behind reverse proxy...looking for header value %s', REVERSE_PROXY_HEADER) ip = request.META.get(REVERSE_PROXY_HEADER, '') if ip == '': raise Warning('Axes is configured for operation behind a reverse proxy but could not find '\ @@ -76,6 +85,7 @@ def get_ip(request): 'to make sure this header value is being passed.'.format(REVERSE_PROXY_HEADER)) return ip + def get_lockout_url(): return getattr(settings, 'AXES_LOCKOUT_URL', None) @@ -110,12 +120,6 @@ def ip_in_blacklist(ip): return False -log = logging.getLogger(LOGGER) -if VERBOSE: - log.info('AXES: BEGIN LOG') - log.info('Using django-axes ' + axes.get_version()) - - def is_user_lockable(request): """Check if the user has a profile with nolockout If so, then return the value to see if this user is special