Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 73 lines (61 sloc) 2.359 kB
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
1 import logging
fea1592 @freakboy3742 Fixed #14406 -- Added a Python 2.4 compatibility to the logging inter…
freakboy3742 authored
2 import sys
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
3 from django.core import mail
4
5 # Make sure a NullHandler is available
6 # This was added in Python 2.7/3.2
7 try:
8 from logging import NullHandler
9 except ImportError:
10 class NullHandler(logging.Handler):
11 def emit(self, record):
12 pass
13
14 # Make sure that dictConfig is available
15 # This was added in Python 2.7/3.2
16 try:
17 from logging.config import dictConfig
18 except ImportError:
19 from django.utils.dictconfig import dictConfig
20
1386470 @adrianholovaty Removed a bunch more Python 2.4 workarounds now that we don't support…
adrianholovaty authored
21 getLogger = logging.getLogger
fea1592 @freakboy3742 Fixed #14406 -- Added a Python 2.4 compatibility to the logging inter…
freakboy3742 authored
22
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
23 # Ensure the creation of the Django logger
24 # with a null handler. This ensures we don't get any
25 # 'No handlers could be found for logger "django"' messages
fea1592 @freakboy3742 Fixed #14406 -- Added a Python 2.4 compatibility to the logging inter…
freakboy3742 authored
26 logger = getLogger('django')
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
27 if not logger.handlers:
28 logger.addHandler(NullHandler())
29
30 class AdminEmailHandler(logging.Handler):
304a50d @adrianholovaty Fixed #15603 -- Changed the traceback error e-mails not to use HTML b…
adrianholovaty authored
31 def __init__(self, include_html=False):
1386470 @adrianholovaty Removed a bunch more Python 2.4 workarounds now that we don't support…
adrianholovaty authored
32 logging.Handler.__init__(self)
304a50d @adrianholovaty Fixed #15603 -- Changed the traceback error e-mails not to use HTML b…
adrianholovaty authored
33 self.include_html = include_html
34
94af19c @adrianholovaty Changed e-mail to email throughout documentation and codebase. The on…
adrianholovaty authored
35 """An exception log handler that emails log entries to site admins.
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
36
37 If the request is passed as the first argument to the log record,
38 request data will be provided in the
39 """
40 def emit(self, record):
41 import traceback
42 from django.conf import settings
29c4a57 @freakboy3742 Fixed #10863 -- Added HTML support to mail_managers() and mail_admins…
freakboy3742 authored
43 from django.views.debug import ExceptionReporter
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
44
45 try:
1386470 @adrianholovaty Removed a bunch more Python 2.4 workarounds now that we don't support…
adrianholovaty authored
46 request = record.request
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
47 subject = '%s (%s IP): %s' % (
48 record.levelname,
49 (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'),
2a5105a @freakboy3742 Fixed #14973 -- Tweaked the email log handler so that the log message…
freakboy3742 authored
50 record.msg
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
51 )
52 request_repr = repr(request)
53 except:
7ab5ce6 @freakboy3742 Fixed #15628 -- Made the admin error email more useful when there isn…
freakboy3742 authored
54 subject = '%s: %s' % (
55 record.levelname,
56 record.msg
57 )
58
29c4a57 @freakboy3742 Fixed #10863 -- Added HTML support to mail_managers() and mail_admins…
freakboy3742 authored
59 request = None
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
60 request_repr = "Request repr() unavailable"
61
62 if record.exc_info:
29c4a57 @freakboy3742 Fixed #10863 -- Added HTML support to mail_managers() and mail_admins…
freakboy3742 authored
63 exc_info = record.exc_info
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
64 stack_trace = '\n'.join(traceback.format_exception(*record.exc_info))
65 else:
9a82eb6 @freakboy3742 Fixed #14972 -- Ensure that the HTML email logger always produces use…
freakboy3742 authored
66 exc_info = (None, record.msg, None)
24acca4 @freakboy3742 Fixed #12012 -- Added support for logging. Thanks to Vinay Sajip for …
freakboy3742 authored
67 stack_trace = 'No stack trace available'
68
69 message = "%s\n\n%s" % (stack_trace, request_repr)
5fadc86 @jezdez Fixed #14851 -- Swapped an argument order to fix compatibility with P…
jezdez authored
70 reporter = ExceptionReporter(request, is_email=True, *exc_info)
304a50d @adrianholovaty Fixed #15603 -- Changed the traceback error e-mails not to use HTML b…
adrianholovaty authored
71 html_message = self.include_html and reporter.get_traceback_html() or None
1386470 @adrianholovaty Removed a bunch more Python 2.4 workarounds now that we don't support…
adrianholovaty authored
72 mail.mail_admins(subject, message, fail_silently=True, html_message=html_message)
Something went wrong with that request. Please try again.