Ticket #15603: logger.diff

File logger.diff, 2.8 KB (added by kmtracey, 4 years ago)

Updated patch to include doc

  • docs/topics/logging.txt

     
    327327          message to stdout. This handler uses the `simple` output
    328328          format.
    329329
    330         * ``mail_admins``, an AdminEmailHandler, which will email any
     330        * ``mail_admins``, an AdminEmailHandler, which will e-mail any
    331331          ``ERROR`` level message to the site admins. This handler uses
    332332          the ``special`` filter.
    333333
     
    468468Django provides one log handler in addition to those provided by the
    469469Python logging module.
    470470
    471 .. class:: AdminEmailHandler()
     471.. class:: AdminEmailHandler([include_html=False])
    472472
    473     This handler sends an email to the site admins for each log
     473    This handler sends an e-mail to the site admins for each log
    474474    message it receives.
    475475
    476476    If the log record contains a 'request' attribute, the full details
    477     of the request will be included in the email.
     477    of the request will be included in the e-mail.
    478478
    479479    If the log record contains stack trace information, that stack
    480     trace will be included in the email.
     480    trace will be included in the e-mail.
     481
     482    The ``include_html`` argument of ``AdminEmailHandler`` is used to
     483    control whether traceback e-mail sent includes an HTML attachment
     484    containing the full content of the debug page that would be produced
     485    if ``DEBUG`` was enabled. To set this value in your configuration, include
     486    it in the handler definition for ``django.utils.log.AdminEmailHandler``,
     487    for example::
     488
     489        'handlers': {
     490            'mail_admins': {
     491                'level': 'ERROR',
     492                'class': 'django.utils.log.AdminEmailHandler',
     493                'include_html': True,
     494            }
     495        },
     496     
  • django/utils/log.py

     
    4848    logger.addHandler(NullHandler())
    4949
    5050class AdminEmailHandler(logging.Handler):
     51    def __init__(self, include_html=False):
     52        logging.Handler.__init__(self)       
     53        self.include_html = include_html
     54
    5155    """An exception log handler that emails log entries to site admins
    5256
    5357    If the request is passed as the first argument to the log record,
     
    8892
    8993        message = "%s\n\n%s" % (stack_trace, request_repr)
    9094        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
    9296        mail.mail_admins(subject, message, fail_silently=True,
    9397                         html_message=html_message)
Back to Top