コード例 #1
0
ファイル: log.py プロジェクト: timothyclemans/djangocg
    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)
コード例 #2
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_message_only(self):
     reporter = ExceptionReporter(None, None, "I'm a little teapot", None)
     html = reporter.get_traceback_html()
     self.assertIn('<h1>Report</h1>', html)
     self.assertIn('<pre class="exception_value">I&#39;m a little teapot</pre>', html)
     self.assertNotIn('<th>Request Method:</th>', html)
     self.assertNotIn('<th>Request URL:</th>', html)
     self.assertNotIn('<th>Exception Type:</th>', html)
     self.assertNotIn('<th>Exception Value:</th>', html)
     self.assertNotIn('<h2>Traceback ', html)
     self.assertIn('<h2>Request information</h2>', html)
     self.assertIn('<p>Request data not supplied</p>', html)
コード例 #3
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_request_and_message(self):
     "A message can be provided in addition to a request"
     request = self.rf.get('/test_view/')
     reporter = ExceptionReporter(request, None, "I'm a little teapot", None)
     html = reporter.get_traceback_html()
     self.assertIn('<h1>Report at /test_view/</h1>', html)
     self.assertIn('<pre class="exception_value">I&#39;m a little teapot</pre>', html)
     self.assertIn('<th>Request Method:</th>', html)
     self.assertIn('<th>Request URL:</th>', html)
     self.assertNotIn('<th>Exception Type:</th>', html)
     self.assertNotIn('<th>Exception Value:</th>', html)
     self.assertNotIn('<h2>Traceback ', html)
     self.assertIn('<h2>Request information</h2>', html)
     self.assertNotIn('<p>Request data not supplied</p>', html)
コード例 #4
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_no_exception(self):
     "An exception report can be generated for just a request"
     request = self.rf.get('/test_view/')
     reporter = ExceptionReporter(request, None, None, None)
     html = reporter.get_traceback_html()
     self.assertIn('<h1>Report at /test_view/</h1>', html)
     self.assertIn('<pre class="exception_value">No exception supplied</pre>', html)
     self.assertIn('<th>Request Method:</th>', html)
     self.assertIn('<th>Request URL:</th>', html)
     self.assertNotIn('<th>Exception Type:</th>', html)
     self.assertNotIn('<th>Exception Value:</th>', html)
     self.assertNotIn('<h2>Traceback ', html)
     self.assertIn('<h2>Request information</h2>', html)
     self.assertNotIn('<p>Request data not supplied</p>', html)
コード例 #5
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_no_request(self):
     "An exception report can be generated without request"
     try:
         raise ValueError("Can't find my keys")
     except ValueError:
         exc_type, exc_value, tb = sys.exc_info()
     reporter = ExceptionReporter(None, exc_type, exc_value, tb)
     text = reporter.get_traceback_text()
     self.assertIn('ValueError', text)
     self.assertIn("Can't find my keys", text)
     self.assertNotIn('Request Method:', text)
     self.assertNotIn('Request URL:', text)
     self.assertIn('Exception Type:', text)
     self.assertIn('Exception Value:', text)
     self.assertIn('Traceback:', text)
     self.assertIn('Request data not supplied', text)
コード例 #6
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_no_request(self):
     "An exception report can be generated without request"
     try:
         raise ValueError("Can't find my keys")
     except ValueError:
         exc_type, exc_value, tb = sys.exc_info()
     reporter = ExceptionReporter(None, exc_type, exc_value, tb)
     html = reporter.get_traceback_html()
     self.assertIn('<h1>ValueError</h1>', html)
     self.assertIn('<pre class="exception_value">Can&#39;t find my keys</pre>', html)
     self.assertNotIn('<th>Request Method:</th>', html)
     self.assertNotIn('<th>Request URL:</th>', html)
     self.assertIn('<th>Exception Type:</th>', html)
     self.assertIn('<th>Exception Value:</th>', html)
     self.assertIn('<h2>Traceback ', html)
     self.assertIn('<h2>Request information</h2>', html)
     self.assertIn('<p>Request data not supplied</p>', html)
コード例 #7
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_request_and_exception(self):
     "A simple exception report can be generated"
     try:
         request = self.rf.get('/test_view/')
         raise ValueError("Can't find my keys")
     except ValueError:
         exc_type, exc_value, tb = sys.exc_info()
     reporter = ExceptionReporter(request, exc_type, exc_value, tb)
     html = reporter.get_traceback_html()
     self.assertIn('<h1>ValueError at /test_view/</h1>', html)
     self.assertIn('<pre class="exception_value">Can&#39;t find my keys</pre>', html)
     self.assertIn('<th>Request Method:</th>', html)
     self.assertIn('<th>Request URL:</th>', html)
     self.assertIn('<th>Exception Type:</th>', html)
     self.assertIn('<th>Exception Value:</th>', html)
     self.assertIn('<h2>Traceback ', html)
     self.assertIn('<h2>Request information</h2>', html)
     self.assertNotIn('<p>Request data not supplied</p>', html)
コード例 #8
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_request_and_exception(self):
     "A simple exception report can be generated"
     try:
         request = self.rf.get('/test_view/')
         raise ValueError("Can't find my keys")
     except ValueError:
         exc_type, exc_value, tb = sys.exc_info()
     reporter = ExceptionReporter(request, exc_type, exc_value, tb)
     text = reporter.get_traceback_text()
     self.assertIn('ValueError at /test_view/', text)
     self.assertIn("Can't find my keys", text)
     self.assertIn('Request Method:', text)
     self.assertIn('Request URL:', text)
     self.assertIn('Exception Type:', text)
     self.assertIn('Exception Value:', text)
     self.assertIn('Traceback:', text)
     self.assertIn('Request information:', text)
     self.assertNotIn('Request data not supplied', text)
コード例 #9
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_message_only(self):
     reporter = ExceptionReporter(None, None, "I'm a little teapot", None)
     text = reporter.get_traceback_text()
コード例 #10
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_request_and_message(self):
     "A message can be provided in addition to a request"
     request = self.rf.get('/test_view/')
     reporter = ExceptionReporter(request, None, "I'm a little teapot", None)
     text = reporter.get_traceback_text()
コード例 #11
0
ファイル: debug.py プロジェクト: timothyclemans/djangocg
 def test_no_exception(self):
     "An exception report can be generated for just a request"
     request = self.rf.get('/test_view/')
     reporter = ExceptionReporter(request, None, None, None)
     text = reporter.get_traceback_text()