當前位置: 首頁>>代碼示例>>Python>>正文


Python debug.ExceptionReporter方法代碼示例

本文整理匯總了Python中django.views.debug.ExceptionReporter方法的典型用法代碼示例。如果您正苦於以下問題:Python debug.ExceptionReporter方法的具體用法?Python debug.ExceptionReporter怎麽用?Python debug.ExceptionReporter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.views.debug的用法示例。


在下文中一共展示了debug.ExceptionReporter方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: emit

# 需要導入模塊: from django.views import debug [as 別名]
# 或者: from django.views.debug import ExceptionReporter [as 別名]
def emit(self, record):
        try:
            request = record.request
            subject = '%s (%s IP): %s' % (
                record.levelname,
                ('internal' if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
                 else 'EXTERNAL'),
                record.getMessage()
            )
            filter = get_exception_reporter_filter(request)
            request_repr = '\n{}'.format(force_text(filter.get_request_repr(request)))
        except Exception:
            subject = '%s: %s' % (
                record.levelname,
                record.getMessage()
            )
            request = None
            request_repr = "unavailable"
        subject = self.format_subject(subject)

        if record.exc_info:
            exc_info = record.exc_info
        else:
            exc_info = (None, record.getMessage(), None)

        message = "%s\n\nRequest repr(): %s" % (self.format(record), request_repr)
        reporter = ExceptionReporter(request, is_email=True, *exc_info)
        html_message = reporter.get_traceback_html() if self.include_html else None
        self.send_mail(subject, message, fail_silently=True, html_message=html_message) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:31,代碼來源:log.py

示例2: emit

# 需要導入模塊: from django.views import debug [as 別名]
# 或者: from django.views.debug import ExceptionReporter [as 別名]
def emit(self, record):
        try:
            request = record.request
            subject = '%s (%s IP): %s' % (
                record.levelname,
                ('internal' if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
                 else 'EXTERNAL'),
                record.getMessage()
            )
        except Exception:
            subject = '%s: %s' % (
                record.levelname,
                record.getMessage()
            )
            request = None
        subject = self.format_subject(subject)

        # Since we add a nicely formatted traceback on our own, create a copy
        # of the log record without the exception data.
        no_exc_record = copy(record)
        no_exc_record.exc_info = None
        no_exc_record.exc_text = None

        if record.exc_info:
            exc_info = record.exc_info
        else:
            exc_info = (None, record.getMessage(), None)

        reporter = ExceptionReporter(request, is_email=True, *exc_info)
        message = "%s\n\n%s" % (self.format(no_exc_record), reporter.get_traceback_text())
        html_message = reporter.get_traceback_html() if self.include_html else None
        self.send_mail(subject, message, fail_silently=True, html_message=html_message) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:34,代碼來源:log.py

示例3: _send_email

# 需要導入模塊: from django.views import debug [as 別名]
# 或者: from django.views.debug import ExceptionReporter [as 別名]
def _send_email(self, subject, message, exc_info=None, attachments=None,
                    extra_recipients: Optional[List[str]] = None):
        """
        Helper method mimicking :class:`AdminEmailHandler` - if exception is available renders traceback as HTML message
        content
        """
        if exc_info is not None:
            reporter = ExceptionReporter(None, is_email=True, *exc_info)
            html_message = reporter.get_traceback_html()
            attachments.append(("debug.html", html_message, "text/html"))

        self.logger.info("Sending message to admins: %s - %s", subject, message)
        self._mail_admins_with_attachment(subject, message, attachments=attachments, extra_recipients=extra_recipients) 
開發者ID:open-craft,項目名稱:opencraft,代碼行數:15,代碼來源:utilities.py

示例4: emit

# 需要導入模塊: from django.views import debug [as 別名]
# 或者: from django.views.debug import ExceptionReporter [as 別名]
def emit(self, record):
        try:
            request = record.request
            subject = '%s (%s IP): %s' % (
                record.levelname,
                (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
                 and 'internal' or 'EXTERNAL'),
                record.getMessage()
            )
            filter = get_exception_reporter_filter(request)
            request_repr = filter.get_request_repr(request)
        except Exception:
            subject = '%s: %s' % (
                record.levelname,
                record.getMessage()
            )
            request = None
            request_repr = "Request repr() unavailable."
        subject = self.format_subject(subject)

        if record.exc_info:
            exc_info = record.exc_info
            stack_trace = '\n'.join(traceback.format_exception(*record.exc_info))
        else:
            exc_info = (None, record.getMessage(), None)
            stack_trace = 'No stack trace available'

        message = "%s\n\n%s" % (stack_trace, request_repr)
        reporter = ExceptionReporter(request, is_email=True, *exc_info)
        html_message = self.include_html and reporter.get_traceback_html() or None
        mail.mail_admins(subject, message, fail_silently=True, html_message=html_message) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:33,代碼來源:log.py

示例5: emit

# 需要導入模塊: from django.views import debug [as 別名]
# 或者: from django.views.debug import ExceptionReporter [as 別名]
def emit(self, record):

        try:
            request = record.request
        except Exception:
            request = None

        subject = '%s: %s' % (
            record.levelname,
            record.getMessage()
        )
        subject = subject.replace('\n', '\\n').replace('\r', '\\r')

        # Since we add a nicely formatted traceback on our own, create a copy
        # of the log record without the exception data.
        no_exc_record = copy(record)
        no_exc_record.exc_info = None
        no_exc_record.exc_text = None

        if record.exc_info:
            exc_info = record.exc_info
        else:
            exc_info = (None, record.getMessage(), None)
        if settings.HACKATHON_DEV_EMAILS:
            reporter = ExceptionReporter(request, is_email=True, *exc_info)
            message = "%s\n\n%s" % (self.format(no_exc_record), reporter.get_traceback_text())
            html_message = reporter.get_traceback_html()
            msg = EmailMultiAlternatives(subject,
                                         message,
                                         'server@' + settings.HACKATHON_DOMAIN,
                                         settings.HACKATHON_DEV_EMAILS)
            msg.attach_alternative(html_message, 'text/html')
            msg.send(fail_silently=True) 
開發者ID:HackAssistant,項目名稱:registration,代碼行數:35,代碼來源:log.py

示例6: celery_error_handler

# 需要導入模塊: from django.views import debug [as 別名]
# 或者: from django.views.debug import ExceptionReporter [as 別名]
def celery_error_handler(task_id, exception, traceback, einfo, *args, **kwargs):
    if settings.DEBUG:
        return

    mail_subject = "Task exception - {}".format(exception)
    mail_subject = mail_subject.replace("\n", " ")[:250]

    reporter = ExceptionReporter(None, einfo.type, exception, traceback)
    mail_text = reporter.get_traceback_text()

    mail_admins(mail_subject, mail_text) 
開發者ID:helfertool,項目名稱:helfertool,代碼行數:13,代碼來源:celery.py


注:本文中的django.views.debug.ExceptionReporter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。