Ticket #17281: django-17281.2.diff
File django-17281.2.diff, 3.1 KB (added by , 13 years ago) |
---|
-
AUTHORS
diff --git a/AUTHORS b/AUTHORS index 9ffd6cd..d2eb4a1 100644
a b answer newbie questions, and generally made Django that much better: 450 450 Manuel Saelices <msaelices@yaco.es> 451 451 Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/> 452 452 Vinay Sajip <vinay_sajip@yahoo.co.uk> 453 Bartolome Sanchez Salado <i42sasab@uco.es> 454 Marcin Wróbel 453 455 Kadesarin Sanjek 454 456 Massimo Scamarcia <massimo.scamarcia@gmail.com> 455 457 Paulo Scardine <paulo@scardine.com.br> -
django/utils/log.py
diff --git a/django/utils/log.py b/django/utils/log.py index 8ce37f5..8be0a83 100644
a b class AdminEmailHandler(logging.Handler): 59 59 ) 60 60 request = None 61 61 request_repr = "Request repr() unavailable." 62 subject = self.format_subject_for_email(subject) 62 63 63 64 if record.exc_info: 64 65 exc_info = record.exc_info … … class AdminEmailHandler(logging.Handler): 72 73 html_message = self.include_html and reporter.get_traceback_html() or None 73 74 mail.mail_admins(subject, message, fail_silently=True, html_message=html_message) 74 75 76 def format_subject_for_email(self, subject): 77 """ 78 Escape CR and LF characters, limit length. 79 RFC2822 - hard limit is 998 minus 'Subject: ' equals 989 80 """ 81 if subject is None: 82 return 'None' 83 else: 84 subject_repr = subject.replace('\n', '\\n').replace('\r', '\\r') 85 return subject_repr[:989] 86 75 87 76 88 class CallbackFilter(logging.Filter): 77 89 """ -
tests/regressiontests/logging_tests/tests.py
diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py index a2c178c..f91cfb9 100644
a b class AdminEmailHandlerTest(TestCase): 160 160 161 161 # Restore original filters 162 162 admin_email_handler.filters = orig_filters 163 164 @override_settings( 165 ADMINS=(('admin', 'admin@example.com'),), 166 EMAIL_SUBJECT_PREFIX='', 167 DEBUG=False, 168 ) 169 def test_subject_accepts_newlines(self): 170 message = u'Message \r\n with newslines' 171 expected_subject = u'ERROR: Message \\r\\n with newslines' 172 173 self.assertEqual(len(mail.outbox), 0) 174 175 logger = getLogger('django.request') 176 logger.error(message) 177 178 self.assertEqual(len(mail.outbox), 1) 179 self.assertFalse('\n' in mail.outbox[0].subject) 180 self.assertEqual(mail.outbox[0].subject, expected_subject) 181 182 @override_settings( 183 ADMINS=(('admin', 'admin@example.com'),), 184 EMAIL_SUBJECT_PREFIX='', 185 DEBUG=False, 186 ) 187 def test_truncate_subject(self): 188 message = '0123456789' * 100 189 expected_subject = 'ERROR: ' + '0123456789' * 98 + '01' 190 191 self.assertEqual(len(mail.outbox), 0) 192 193 logger = getLogger('django.request') 194 logger.error(message) 195 196 self.assertEqual(len(mail.outbox), 1) 197 self.assertEqual(mail.outbox[0].subject, expected_subject)