Ticket #14406: t14406.diff

File t14406.diff, 7.8 KB (added by Russell Keith-Magee, 14 years ago)

Possible fix for Python 2.4 logging.

  • django/core/handlers/base.py

    diff -r bea53389c204 django/core/handlers/base.py
    a b  
    1 import logging
    21import sys
    32
    43from django import http
    54from django.core import signals
    65from django.utils.encoding import force_unicode
    76from django.utils.importlib import import_module
     7from django.utils.log import getLogger
    88
    9 logger = logging.getLogger('django.request')
     9logger = getLogger('django.request')
    1010
    1111
    1212class BaseHandler(object):
  • django/core/handlers/modpython.py

    diff -r bea53389c204 django/core/handlers/modpython.py
    a b  
    1 import logging
    21import os
    32from pprint import pformat
    43import sys
     
    109from django.core.urlresolvers import set_script_prefix
    1110from django.utils import datastructures
    1211from django.utils.encoding import force_unicode, smart_str, iri_to_uri
     12from django.utils.log import getLogger
    1313
    14 logger = logging.getLogger('django.request')
     14logger = getLogger('django.request')
    1515
    1616
    1717# NOTE: do *not* import settings (or any module which eventually imports
  • django/core/handlers/wsgi.py

    diff -r bea53389c204 django/core/handlers/wsgi.py
    a b  
    1 import logging
    21from pprint import pformat
    32import sys
    43from threading import Lock
     
    1312from django.core.urlresolvers import set_script_prefix
    1413from django.utils import datastructures
    1514from django.utils.encoding import force_unicode, iri_to_uri
     15from django.utils.log import getLogger
    1616
    17 logger = logging.getLogger('django.request')
     17logger = getLogger('django.request')
    1818
    1919
    2020# See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  • django/db/backends/util.py

    diff -r bea53389c204 django/db/backends/util.py
    a b  
    11import datetime
    22import decimal
    3 import logging
    43from time import time
    54
    65from django.utils.hashcompat import md5_constructor
     6from django.utils.log import getLogger
    77
    8 logger = logging.getLogger('django.db.backends')
     8logger = getLogger('django.db.backends')
    99
    1010class CursorDebugWrapper(object):
    1111    def __init__(self, cursor, db):
  • django/middleware/common.py

    diff -r bea53389c204 django/middleware/common.py
    a b  
    1 import logging
    21import re
    32
    43from django.conf import settings
     
    76from django.utils.http import urlquote
    87from django.core import urlresolvers
    98from django.utils.hashcompat import md5_constructor
     9from django.utils.log import getLogger
    1010
    11 logger = logging.getLogger('django.request')
     11logger = getLogger('django.request')
    1212
    1313
    1414class CommonMiddleware(object):
  • django/middleware/csrf.py

    diff -r bea53389c204 django/middleware/csrf.py
    a b  
    66"""
    77
    88import itertools
    9 import logging
    109import re
    1110import random
    1211
     
    1413from django.core.urlresolvers import get_callable
    1514from django.utils.cache import patch_vary_headers
    1615from django.utils.hashcompat import md5_constructor
     16from django.utils.log import getLogger
    1717from django.utils.safestring import mark_safe
    1818
    1919_POST_FORM_RE = \
     
    2121
    2222_HTML_TYPES = ('text/html', 'application/xhtml+xml')
    2323
    24 logger = logging.getLogger('django.request')
     24logger = getLogger('django.request')
    2525
    2626# Use the system (hardware-based) random number generator if it exists.
    2727if hasattr(random, 'SystemRandom'):
  • django/utils/log.py

    diff -r bea53389c204 django/utils/log.py
    a b  
    11import logging
     2import sys
    23from django.core import mail
    34
    45# Make sure a NullHandler is available
     
    1718except ImportError:
    1819    from django.utils.dictconfig import dictConfig
    1920
     21if sys.version_info < (2, 5):
     22    class LoggerCompat(object):
     23        def __init__(self, logger):
     24            self._logger = logger
     25
     26        def __getattr__(self, name):
     27            val = getattr(self._logger, name)
     28            if callable(val):
     29                def _wrapper(*args, **kwargs):
     30                    # Python 2.4 logging module doesn't support 'extra' parameter to
     31                    # methods of Logger
     32                    kwargs.pop('extra', None)
     33                    return val(*args, **kwargs)
     34                return _wrapper
     35            else:
     36                return val
     37
     38    def getLogger(name=None):
     39        return LoggerCompat(logging.getLogger(name=name))
     40else:
     41    getLogger = logging.getLogger
     42
    2043# Ensure the creation of the Django logger
    2144# with a null handler. This ensures we don't get any
    2245# 'No handlers could be found for logger "django"' messages
    23 logger = logging.getLogger('django')
     46logger = getLogger('django')
    2447if not logger.handlers:
    2548    logger.addHandler(NullHandler())
    2649
     
    3558        from django.conf import settings
    3659
    3760        try:
    38             request = record.request
     61            if sys.version_info < (2,5):
     62                # A nasty workaround required because Python 2.4's logging
     63                # module doesn't support passing in extra context.
     64                # For this handler, the only extra data we need is the
     65                # request, and that's in the top stack frame.
     66                request = record.exc_info[2].tb_frame.f_locals['request']
     67            else:
     68                request = record.request
    3969
    4070            subject = '%s (%s IP): %s' % (
    4171                record.levelname,
  • django/views/decorators/http.py

    diff -r bea53389c204 django/views/decorators/http.py
    a b  
    1010from calendar import timegm
    1111from datetime import timedelta
    1212from email.Utils import formatdate
    13 import logging
    1413
    1514from django.utils.decorators import decorator_from_middleware, available_attrs
    1615from django.utils.http import parse_etags, quote_etag
     16from django.utils.log import getLogger
    1717from django.middleware.http import ConditionalGetMiddleware
    1818from django.http import HttpResponseNotAllowed, HttpResponseNotModified, HttpResponse
    1919
    2020conditional_page = decorator_from_middleware(ConditionalGetMiddleware)
    2121
    22 logger = logging.getLogger('django.request')
     22logger = getLogger('django.request')
    2323
    2424
    2525def require_http_methods(request_method_list):
  • django/views/generic/simple.py

    diff -r bea53389c204 django/views/generic/simple.py
    a b  
    1 import logging
    2 
    31from django.template import loader, RequestContext
    42from django.http import HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect, HttpResponseGone
     3from django.utils.log import getLogger
    54
    6 logger = logging.getLogger('django.request')
     5logger = getLogger('django.request')
    76
    87
    98def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs):
  • docs/topics/logging.txt

    diff -r bea53389c204 docs/topics/logging.txt
    a b  
    411411    * ``request``: The request object that generated the logging
    412412      message.
    413413
     414.. note::
     415    Due to a limitation in the logging library, this extra
     416    context is not available if you are using Python 2.4.
     417
    414418``django.db.backends``
    415419~~~~~~~~~~~~~~~~~~~~~~
    416420
     
    424428    * ``sql``: The SQL statement that was executed.
    425429    * ``params``: The parameters that were used in the SQL call.
    426430
     431.. note::
     432    Due to a limitation in the logging library, this extra
     433    context is not available if you are using Python 2.4.
     434
    427435Handlers
    428436--------
    429437
Back to Top