当前位置: 首页>>代码示例>>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;未经允许,请勿转载。