diff -r bea53389c204 django/core/handlers/base.py
a
|
b
|
|
1 | | import logging |
2 | 1 | import sys |
3 | 2 | |
4 | 3 | from django import http |
5 | 4 | from django.core import signals |
6 | 5 | from django.utils.encoding import force_unicode |
7 | 6 | from django.utils.importlib import import_module |
| 7 | from django.utils.log import getLogger |
8 | 8 | |
9 | | logger = logging.getLogger('django.request') |
| 9 | logger = getLogger('django.request') |
10 | 10 | |
11 | 11 | |
12 | 12 | class BaseHandler(object): |
diff -r bea53389c204 django/core/handlers/modpython.py
a
|
b
|
|
1 | | import logging |
2 | 1 | import os |
3 | 2 | from pprint import pformat |
4 | 3 | import sys |
… |
… |
|
10 | 9 | from django.core.urlresolvers import set_script_prefix |
11 | 10 | from django.utils import datastructures |
12 | 11 | from django.utils.encoding import force_unicode, smart_str, iri_to_uri |
| 12 | from django.utils.log import getLogger |
13 | 13 | |
14 | | logger = logging.getLogger('django.request') |
| 14 | logger = getLogger('django.request') |
15 | 15 | |
16 | 16 | |
17 | 17 | # NOTE: do *not* import settings (or any module which eventually imports |
diff -r bea53389c204 django/core/handlers/wsgi.py
a
|
b
|
|
1 | | import logging |
2 | 1 | from pprint import pformat |
3 | 2 | import sys |
4 | 3 | from threading import Lock |
… |
… |
|
13 | 12 | from django.core.urlresolvers import set_script_prefix |
14 | 13 | from django.utils import datastructures |
15 | 14 | from django.utils.encoding import force_unicode, iri_to_uri |
| 15 | from django.utils.log import getLogger |
16 | 16 | |
17 | | logger = logging.getLogger('django.request') |
| 17 | logger = getLogger('django.request') |
18 | 18 | |
19 | 19 | |
20 | 20 | # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html |
diff -r bea53389c204 django/db/backends/util.py
a
|
b
|
|
1 | 1 | import datetime |
2 | 2 | import decimal |
3 | | import logging |
4 | 3 | from time import time |
5 | 4 | |
6 | 5 | from django.utils.hashcompat import md5_constructor |
| 6 | from django.utils.log import getLogger |
7 | 7 | |
8 | | logger = logging.getLogger('django.db.backends') |
| 8 | logger = getLogger('django.db.backends') |
9 | 9 | |
10 | 10 | class CursorDebugWrapper(object): |
11 | 11 | def __init__(self, cursor, db): |
diff -r bea53389c204 django/middleware/common.py
a
|
b
|
|
1 | | import logging |
2 | 1 | import re |
3 | 2 | |
4 | 3 | from django.conf import settings |
… |
… |
|
7 | 6 | from django.utils.http import urlquote |
8 | 7 | from django.core import urlresolvers |
9 | 8 | from django.utils.hashcompat import md5_constructor |
| 9 | from django.utils.log import getLogger |
10 | 10 | |
11 | | logger = logging.getLogger('django.request') |
| 11 | logger = getLogger('django.request') |
12 | 12 | |
13 | 13 | |
14 | 14 | class CommonMiddleware(object): |
diff -r bea53389c204 django/middleware/csrf.py
a
|
b
|
|
6 | 6 | """ |
7 | 7 | |
8 | 8 | import itertools |
9 | | import logging |
10 | 9 | import re |
11 | 10 | import random |
12 | 11 | |
… |
… |
|
14 | 13 | from django.core.urlresolvers import get_callable |
15 | 14 | from django.utils.cache import patch_vary_headers |
16 | 15 | from django.utils.hashcompat import md5_constructor |
| 16 | from django.utils.log import getLogger |
17 | 17 | from django.utils.safestring import mark_safe |
18 | 18 | |
19 | 19 | _POST_FORM_RE = \ |
… |
… |
|
21 | 21 | |
22 | 22 | _HTML_TYPES = ('text/html', 'application/xhtml+xml') |
23 | 23 | |
24 | | logger = logging.getLogger('django.request') |
| 24 | logger = getLogger('django.request') |
25 | 25 | |
26 | 26 | # Use the system (hardware-based) random number generator if it exists. |
27 | 27 | if hasattr(random, 'SystemRandom'): |
diff -r bea53389c204 django/utils/log.py
a
|
b
|
|
1 | 1 | import logging |
| 2 | import sys |
2 | 3 | from django.core import mail |
3 | 4 | |
4 | 5 | # Make sure a NullHandler is available |
… |
… |
|
17 | 18 | except ImportError: |
18 | 19 | from django.utils.dictconfig import dictConfig |
19 | 20 | |
| 21 | if 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)) |
| 40 | else: |
| 41 | getLogger = logging.getLogger |
| 42 | |
20 | 43 | # Ensure the creation of the Django logger |
21 | 44 | # with a null handler. This ensures we don't get any |
22 | 45 | # 'No handlers could be found for logger "django"' messages |
23 | | logger = logging.getLogger('django') |
| 46 | logger = getLogger('django') |
24 | 47 | if not logger.handlers: |
25 | 48 | logger.addHandler(NullHandler()) |
26 | 49 | |
… |
… |
|
35 | 58 | from django.conf import settings |
36 | 59 | |
37 | 60 | 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 |
39 | 69 | |
40 | 70 | subject = '%s (%s IP): %s' % ( |
41 | 71 | record.levelname, |
diff -r bea53389c204 django/views/decorators/http.py
a
|
b
|
|
10 | 10 | from calendar import timegm |
11 | 11 | from datetime import timedelta |
12 | 12 | from email.Utils import formatdate |
13 | | import logging |
14 | 13 | |
15 | 14 | from django.utils.decorators import decorator_from_middleware, available_attrs |
16 | 15 | from django.utils.http import parse_etags, quote_etag |
| 16 | from django.utils.log import getLogger |
17 | 17 | from django.middleware.http import ConditionalGetMiddleware |
18 | 18 | from django.http import HttpResponseNotAllowed, HttpResponseNotModified, HttpResponse |
19 | 19 | |
20 | 20 | conditional_page = decorator_from_middleware(ConditionalGetMiddleware) |
21 | 21 | |
22 | | logger = logging.getLogger('django.request') |
| 22 | logger = getLogger('django.request') |
23 | 23 | |
24 | 24 | |
25 | 25 | def require_http_methods(request_method_list): |
diff -r bea53389c204 django/views/generic/simple.py
a
|
b
|
|
1 | | import logging |
2 | | |
3 | 1 | from django.template import loader, RequestContext |
4 | 2 | from django.http import HttpResponse, HttpResponseRedirect, HttpResponsePermanentRedirect, HttpResponseGone |
| 3 | from django.utils.log import getLogger |
5 | 4 | |
6 | | logger = logging.getLogger('django.request') |
| 5 | logger = getLogger('django.request') |
7 | 6 | |
8 | 7 | |
9 | 8 | def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs): |
diff -r bea53389c204 docs/topics/logging.txt
a
|
b
|
|
411 | 411 | * ``request``: The request object that generated the logging |
412 | 412 | message. |
413 | 413 | |
| 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 | |
414 | 418 | ``django.db.backends`` |
415 | 419 | ~~~~~~~~~~~~~~~~~~~~~~ |
416 | 420 | |
… |
… |
|
424 | 428 | * ``sql``: The SQL statement that was executed. |
425 | 429 | * ``params``: The parameters that were used in the SQL call. |
426 | 430 | |
| 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 | |
427 | 435 | Handlers |
428 | 436 | -------- |
429 | 437 | |