Mercurial > public > sg101
annotate antispam/decorators.py @ 861:e4f8d87c3d30
Configure Markdown logger to reduce noise in logs.
Markdown is logging at the INFO level whenever it loads an extension.
This looks like it has been fixed in master at GitHub. But until then
we will explicitly configure the MARKDOWN logger to log at WARNING
or higher.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 01 Dec 2014 18:36:27 -0600 |
parents | 4a49d4ac319f |
children |
rev | line source |
---|---|
bgneal@472 | 1 """ |
bgneal@472 | 2 This module contains decorators for the antispam application. |
bgneal@472 | 3 |
bgneal@472 | 4 """ |
bgneal@472 | 5 from functools import wraps |
bgneal@690 | 6 import logging |
bgneal@472 | 7 |
bgneal@472 | 8 |
bgneal@690 | 9 def log_auth_failures(auth_type): |
bgneal@472 | 10 |
bgneal@472 | 11 def decorator(fn): |
bgneal@690 | 12 logger = logging.getLogger('auth') |
bgneal@472 | 13 |
bgneal@472 | 14 @wraps(fn) |
bgneal@472 | 15 def wrapped(request, *args, **kwargs): |
bgneal@472 | 16 |
bgneal@472 | 17 response = fn(request, *args, **kwargs) |
bgneal@472 | 18 |
bgneal@472 | 19 if request.method == 'POST': |
bgneal@505 | 20 |
bgneal@692 | 21 # Figure out if the view succeeded; success means a redirect is |
bgneal@692 | 22 # about to occur. |
bgneal@692 | 23 success = (response and response.has_header('location') and |
bgneal@692 | 24 response.status_code == 302) |
bgneal@505 | 25 |
bgneal@505 | 26 if not success: |
bgneal@690 | 27 username = request.POST.get('username') |
bgneal@690 | 28 username = username if username else '(None)' |
bgneal@690 | 29 logger.error("%s failure from [%s] for %s", |
bgneal@690 | 30 auth_type, |
bgneal@690 | 31 request.META.get('REMOTE_ADDR', '?'), |
bgneal@690 | 32 username) |
bgneal@479 | 33 |
bgneal@472 | 34 return response |
bgneal@472 | 35 |
bgneal@472 | 36 return wrapped |
bgneal@472 | 37 return decorator |