From f0a1633425d5afdaec85e188ce67d647e218ff23 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 9 Feb 2012 18:58:36 +0000 Subject: [PATCH] Fixed #17358 -- Updated logging calls to use official syntax for arguments instead of string interpolation. Thanks, spulec. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17480 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/handlers/base.py | 6 +++--- django/middleware/common.py | 2 +- django/middleware/csrf.py | 8 ++++---- django/views/decorators/http.py | 6 +++--- django/views/generic/base.py | 4 ++-- django/views/generic/simple.py | 2 +- tests/regressiontests/views/views.py | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py index 3606e1853c..a0918bfc41 100644 --- a/django/core/handlers/base.py +++ b/django/core/handlers/base.py @@ -136,7 +136,7 @@ class BaseHandler(object): response = response.render() except http.Http404, e: - logger.warning('Not Found: %s' % request.path, + logger.warning('Not Found: %s', request.path, extra={ 'status_code': 404, 'request': request @@ -155,7 +155,7 @@ class BaseHandler(object): signals.got_request_exception.send(sender=self.__class__, request=request) except exceptions.PermissionDenied: logger.warning( - 'Forbidden (Permission denied): %s' % request.path, + 'Forbidden (Permission denied): %s', request.path, extra={ 'status_code': 403, 'request': request @@ -208,7 +208,7 @@ class BaseHandler(object): if settings.DEBUG_PROPAGATE_EXCEPTIONS: raise - logger.error('Internal Server Error: %s' % request.path, + logger.error('Internal Server Error: %s', request.path, exc_info=exc_info, extra={ 'status_code': 500, diff --git a/django/middleware/common.py b/django/middleware/common.py index 4dd2e14652..aaa094d15a 100644 --- a/django/middleware/common.py +++ b/django/middleware/common.py @@ -42,7 +42,7 @@ class CommonMiddleware(object): if 'HTTP_USER_AGENT' in request.META: for user_agent_regex in settings.DISALLOWED_USER_AGENTS: if user_agent_regex.search(request.META['HTTP_USER_AGENT']): - logger.warning('Forbidden (User agent): %s' % request.path, + logger.warning('Forbidden (User agent): %s', request.path, extra={ 'status_code': 403, 'request': request diff --git a/django/middleware/csrf.py b/django/middleware/csrf.py index 37f92b1d94..d46fc7bcd8 100644 --- a/django/middleware/csrf.py +++ b/django/middleware/csrf.py @@ -134,7 +134,7 @@ class CsrfViewMiddleware(object): # we can use strict Referer checking. referer = request.META.get('HTTP_REFERER') if referer is None: - logger.warning('Forbidden (%s): %s' % (REASON_NO_REFERER, request.path), + logger.warning('Forbidden (%s): %s', REASON_NO_REFERER, request.path, extra={ 'status_code': 403, 'request': request, @@ -146,7 +146,7 @@ class CsrfViewMiddleware(object): good_referer = 'https://%s/' % request.get_host() if not same_origin(referer, good_referer): reason = REASON_BAD_REFERER % (referer, good_referer) - logger.warning('Forbidden (%s): %s' % (reason, request.path), + logger.warning('Forbidden (%s): %s', reason, request.path, extra={ 'status_code': 403, 'request': request, @@ -158,7 +158,7 @@ class CsrfViewMiddleware(object): # No CSRF cookie. For POST requests, we insist on a CSRF cookie, # and in this way we can avoid all CSRF attacks, including login # CSRF. - logger.warning('Forbidden (%s): %s' % (REASON_NO_CSRF_COOKIE, request.path), + logger.warning('Forbidden (%s): %s', REASON_NO_CSRF_COOKIE, request.path, extra={ 'status_code': 403, 'request': request, @@ -177,7 +177,7 @@ class CsrfViewMiddleware(object): request_csrf_token = request.META.get('HTTP_X_CSRFTOKEN', '') if not constant_time_compare(request_csrf_token, csrf_token): - logger.warning('Forbidden (%s): %s' % (REASON_BAD_TOKEN, request.path), + logger.warning('Forbidden (%s): %s', REASON_BAD_TOKEN, request.path, extra={ 'status_code': 403, 'request': request, diff --git a/django/views/decorators/http.py b/django/views/decorators/http.py index 387b869000..d5c4bff744 100644 --- a/django/views/decorators/http.py +++ b/django/views/decorators/http.py @@ -31,7 +31,7 @@ def require_http_methods(request_method_list): @wraps(func, assigned=available_attrs(func)) def inner(request, *args, **kwargs): if request.method not in request_method_list: - logger.warning('Method Not Allowed (%s): %s' % (request.method, request.path), + logger.warning('Method Not Allowed (%s): %s', request.method, request.path, extra={ 'status_code': 405, 'request': request @@ -122,7 +122,7 @@ def condition(etag_func=None, last_modified_func=None): if request.method in ("GET", "HEAD"): response = HttpResponseNotModified() else: - logger.warning('Precondition Failed: %s' % request.path, + logger.warning('Precondition Failed: %s', request.path, extra={ 'status_code': 412, 'request': request @@ -131,7 +131,7 @@ def condition(etag_func=None, last_modified_func=None): response = HttpResponse(status=412) elif if_match and ((not res_etag and "*" in etags) or (res_etag and res_etag not in etags)): - logger.warning('Precondition Failed: %s' % request.path, + logger.warning('Precondition Failed: %s', request.path, extra={ 'status_code': 412, 'request': request diff --git a/django/views/generic/base.py b/django/views/generic/base.py index ea14281a71..f443cebfc0 100644 --- a/django/views/generic/base.py +++ b/django/views/generic/base.py @@ -68,7 +68,7 @@ class View(object): def http_method_not_allowed(self, request, *args, **kwargs): allowed_methods = [m for m in self.http_method_names if hasattr(self, m)] - logger.warning('Method Not Allowed (%s): %s' % (request.method, request.path), + logger.warning('Method Not Allowed (%s): %s', request.method, request.path, extra={ 'status_code': 405, 'request': self.request @@ -157,7 +157,7 @@ class RedirectView(View): else: return http.HttpResponseRedirect(url) else: - logger.warning('Gone: %s' % self.request.path, + logger.warning('Gone: %s', self.request.path, extra={ 'status_code': 410, 'request': self.request diff --git a/django/views/generic/simple.py b/django/views/generic/simple.py index f7b4b1c2b1..f63860a4cf 100644 --- a/django/views/generic/simple.py +++ b/django/views/generic/simple.py @@ -60,7 +60,7 @@ def redirect_to(request, url, permanent=True, query_string=False, **kwargs): klass = permanent and HttpResponsePermanentRedirect or HttpResponseRedirect return klass(url) else: - logger.warning('Gone: %s' % request.path, + logger.warning('Gone: %s', request.path, extra={ 'status_code': 410, 'request': request diff --git a/tests/regressiontests/views/views.py b/tests/regressiontests/views/views.py index f2b4e79322..1d17e6e412 100644 --- a/tests/regressiontests/views/views.py +++ b/tests/regressiontests/views/views.py @@ -149,7 +149,7 @@ def send_log(request, exc_info): ][0] orig_filters = admin_email_handler.filters admin_email_handler.filters = [] - logger.error('Internal Server Error: %s' % request.path, + logger.error('Internal Server Error: %s', request.path, exc_info=exc_info, extra={ 'status_code': 500,