Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15603 -- Changed the traceback error e-mails not to use HTML b…

…y default. It's now configurable with an 'include_html' parameter to AdminEmailHandler. Thanks, kmtracey

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15850 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 304a50d8cac1d185685d212867a2d449c5378e9e 1 parent 2ee7cfc
Adrian Holovaty authored March 16, 2011
8  django/utils/log.py
@@ -48,7 +48,11 @@ def getLogger(name=None):
48 48
     logger.addHandler(NullHandler())
49 49
 
50 50
 class AdminEmailHandler(logging.Handler):
51  
-    """An exception log handler that emails log entries to site admins
  51
+    def __init__(self, include_html=False):
  52
+        logging.Handler.__init__(self)        
  53
+        self.include_html = include_html
  54
+
  55
+    """An exception log handler that e-mails log entries to site admins.
52 56
 
53 57
     If the request is passed as the first argument to the log record,
54 58
     request data will be provided in the
@@ -88,6 +92,6 @@ def emit(self, record):
88 92
 
89 93
         message = "%s\n\n%s" % (stack_trace, request_repr)
90 94
         reporter = ExceptionReporter(request, is_email=True, *exc_info)
91  
-        html_message = reporter.get_traceback_html()
  95
+        html_message = self.include_html and reporter.get_traceback_html() or None
92 96
         mail.mail_admins(subject, message, fail_silently=True,
93 97
                          html_message=html_message)
29  docs/topics/logging.txt
@@ -468,13 +468,38 @@ Handlers
468 468
 Django provides one log handler in addition to those provided by the
469 469
 Python logging module.
470 470
 
471  
-.. class:: AdminEmailHandler()
  471
+.. class:: AdminEmailHandler([include_html=False])
472 472
 
473 473
     This handler sends an e-mail to the site admins for each log
474 474
     message it receives.
475 475
 
476  
-    If the log record contains a 'request' attribute, the full details
  476
+    If the log record contains a ``request`` attribute, the full details
477 477
     of the request will be included in the e-mail.
478 478
 
479 479
     If the log record contains stack trace information, that stack
480 480
     trace will be included in the e-mail.
  481
+
  482
+    The ``include_html`` argument of ``AdminEmailHandler`` is used to
  483
+    control whether the traceback e-mail includes an HTML attachment
  484
+    containing the full content of the debug Web page that would have been
  485
+    produced if ``DEBUG`` were ``True``. To set this value in your
  486
+    configuration, include it in the handler definition for
  487
+    ``django.utils.log.AdminEmailHandler``, like this::
  488
+
  489
+        'handlers': {
  490
+            'mail_admins': {
  491
+                'level': 'ERROR',
  492
+                'class': 'django.utils.log.AdminEmailHandler',
  493
+                'include_html': True,
  494
+            }
  495
+        },
  496
+
  497
+    Note that this HTML version of the e-mail contains a full traceback,
  498
+    with names and values of local variables at each level of the stack, plus
  499
+    the values of your Django settings. This information is potentially very
  500
+    sensitive, and you may not want to send it over e-mail. Consider using
  501
+    something such as `django-sentry`_ to get the best of both worlds -- the
  502
+    rich information of full tracebacks plus the security of *not* sending the
  503
+    information over e-mail.
  504
+
  505
+.. _django-sentry: http://pypi.python.org/pypi/django-sentry

0 notes on commit 304a50d

Please sign in to comment.
Something went wrong with that request. Please try again.