Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #14406 -- Added a Python 2.4 compatibility to the logging inter…

…face. Thanks to Łukasz Rekucki for the report, and to Luke Plant for original patch this was based on.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13989 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fea159282b75130b5f6cf52ec92ddfa09467f3c9 1 parent 57aeb54
Russell Keith-Magee freakboy3742 authored
4 django/core/handlers/base.py
View
@@ -1,12 +1,12 @@
-import logging
import sys
from django import http
from django.core import signals
from django.utils.encoding import force_unicode
from django.utils.importlib import import_module
+from django.utils.log import getLogger
-logger = logging.getLogger('django.request')
+logger = getLogger('django.request')
class BaseHandler(object):
4 django/core/handlers/modpython.py
View
@@ -1,4 +1,3 @@
-import logging
import os
from pprint import pformat
import sys
@@ -10,8 +9,9 @@
from django.core.urlresolvers import set_script_prefix
from django.utils import datastructures
from django.utils.encoding import force_unicode, smart_str, iri_to_uri
+from django.utils.log import getLogger
-logger = logging.getLogger('django.request')
+logger = getLogger('django.request')
# NOTE: do *not* import settings (or any module which eventually imports
4 django/core/handlers/wsgi.py
View
@@ -1,4 +1,3 @@
-import logging
from pprint import pformat
import sys
from threading import Lock
@@ -13,8 +12,9 @@
from django.core.urlresolvers import set_script_prefix
from django.utils import datastructures
from django.utils.encoding import force_unicode, iri_to_uri
+from django.utils.log import getLogger
-logger = logging.getLogger('django.request')
+logger = getLogger('django.request')
# See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
4 django/db/backends/util.py
View
@@ -1,11 +1,11 @@
import datetime
import decimal
-import logging
from time import time
from django.utils.hashcompat import md5_constructor
+from django.utils.log import getLogger
-logger = logging.getLogger('django.db.backends')
+logger = getLogger('django.db.backends')
class CursorDebugWrapper(object):
def __init__(self, cursor, db):
4 django/middleware/common.py
View
@@ -1,4 +1,3 @@
-import logging
import re
from django.conf import settings
@@ -7,8 +6,9 @@
from django.utils.http import urlquote
from django.core import urlresolvers
from django.utils.hashcompat import md5_constructor
+from django.utils.log import getLogger
-logger = logging.getLogger('django.request')
+logger = getLogger('django.request')
class CommonMiddleware(object):
4 django/middleware/csrf.py
View
@@ -6,7 +6,6 @@
"""
import itertools
-import logging
import re
import random
@@ -14,6 +13,7 @@
from django.core.urlresolvers import get_callable
from django.utils.cache import patch_vary_headers
from django.utils.hashcompat import md5_constructor
+from django.utils.log import getLogger
from django.utils.safestring import mark_safe
_POST_FORM_RE = \
@@ -21,7 +21,7 @@
_HTML_TYPES = ('text/html', 'application/xhtml+xml')
-logger = logging.getLogger('django.request')
+logger = getLogger('django.request')
# Use the system (hardware-based) random number generator if it exists.
if hasattr(random, 'SystemRandom'):
34 django/utils/log.py
View
@@ -1,4 +1,5 @@
import logging
+import sys
from django.core import mail
# Make sure a NullHandler is available
@@ -17,10 +18,32 @@ def emit(self, record):
except ImportError:
from django.utils.dictconfig import dictConfig
+if sys.version_info < (2, 5):
+ class LoggerCompat(object):
+ def __init__(self, logger):
+ self._logger = logger
+
+ def __getattr__(self, name):
+ val = getattr(self._logger, name)
+ if callable(val):
+ def _wrapper(*args, **kwargs):
+ # Python 2.4 logging module doesn't support 'extra' parameter to
+ # methods of Logger
+ kwargs.pop('extra', None)
+ return val(*args, **kwargs)
+ return _wrapper
+ else:
+ return val
+
+ def getLogger(name=None):
+ return LoggerCompat(logging.getLogger(name=name))
+else:
+ getLogger = logging.getLogger
+
# Ensure the creation of the Django logger
# with a null handler. This ensures we don't get any
# 'No handlers could be found for logger "django"' messages
-logger = logging.getLogger('django')
+logger = getLogger('django')
if not logger.handlers:
logger.addHandler(NullHandler())
@@ -35,7 +58,14 @@ def emit(self, record):
from django.conf import settings
try:
- request = record.request
+ if sys.version_info < (2,5):
+ # A nasty workaround required because Python 2.4's logging
+ # module doesn't support passing in extra context.
+ # For this handler, the only extra data we need is the
+ # request, and that's in the top stack frame.
+ request = record.exc_info[2].tb_frame.f_locals['request']
+ else:
+ request = record.request
subject = '%s (%s IP): %s' % (
record.levelname,
4 django/views/decorators/http.py
View
@@ -10,16 +10,16 @@
from calendar import timegm
from datetime import timedelta
from email.Utils import formatdate
-import logging
from django.utils.decorators import decorator_from_middleware, available_attrs
from django.utils.http import parse_etags, quote_etag
+from django.utils.log import getLogger
from django.middleware.http import ConditionalGetMiddleware
from django.http import HttpResponseNotAllowed, HttpResponseNotModified, HttpResponse
conditional_page = decorator_from_middleware(ConditionalGetMiddleware)
-logger = logging.getLogger('django.request')
+logger = getLogger('django.request')
def require_http_methods(request_method_list):
5 django/views/generic/simple.py
View
@@ -1,9 +1,8 @@
-import logging
-
from django.template import loader, RequestContext
from django.http import HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect, HttpResponseGone
+from django.utils.log import getLogger
-logger = logging.getLogger('django.request')
+logger = getLogger('django.request')
def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs):
8 docs/topics/logging.txt
View
@@ -411,6 +411,10 @@ Messages to this logger have the following extra context:
* ``request``: The request object that generated the logging
message.
+.. note::
+ Due to a limitation in the logging library, this extra
+ context is not available if you are using Python 2.4.
+
``django.db.backends``
~~~~~~~~~~~~~~~~~~~~~~
@@ -424,6 +428,10 @@ Messages to this logger have the following extra context:
* ``sql``: The SQL statement that was executed.
* ``params``: The parameters that were used in the SQL call.
+.. note::
+ Due to a limitation in the logging library, this extra
+ context is not available if you are using Python 2.4.
+
Handlers
--------
Please sign in to comment.
Something went wrong with that request. Please try again.