Ticket #16736: 16736.adminemailhandler-formatted-subject.diff
File 16736.adminemailhandler-formatted-subject.diff, 2.8 KB (added by , 13 years ago) |
---|
-
django/utils/log.py
diff -r 7fe93a3d9442 django/utils/log.py
a b 53 53 except: 54 54 subject = '%s: %s' % ( 55 55 record.levelname, 56 record. msg56 record.getMessage() 57 57 ) 58 58 request = None 59 59 request_repr = "Request repr() unavailable." … … 62 62 exc_info = record.exc_info 63 63 stack_trace = '\n'.join(traceback.format_exception(*record.exc_info)) 64 64 else: 65 exc_info = (None, record. msg, None)65 exc_info = (None, record.getMessage(), None) 66 66 stack_trace = 'No stack trace available' 67 67 68 68 message = "%s\n\n%s" % (stack_trace, request_repr) -
tests/regressiontests/logging_tests/tests.py
diff -r 7fe93a3d9442 tests/regressiontests/logging_tests/tests.py
a b 4 4 5 5 from django.conf import compat_patch_logging_config 6 6 from django.test import TestCase 7 from django.utils.log import CallbackFilter 7 from django.test.utils import override_settings 8 from django.utils.log import CallbackFilter, getLogger 9 from django.core import mail 10 8 11 9 12 10 13 # logging config prior to using filter with mail_admins … … 115 118 f.filter("a record") 116 119 117 120 self.assertEqual(collector, ["a record"]) 121 122 123 class AdminEmailHandlerTest(TestCase): 124 125 @override_settings(ADMINS=(('whatever admin', 'admin@example.com'),)) 126 def test_accepts_args(self): 127 """ 128 Ensure that user-supplied arguments are merged into the log record's 129 message. 130 Refs #16736. 131 """ 132 133 message = "This is my message, and it says '%s' and '%s'" 134 token1 = 'ping' 135 token2 = 'pong' 136 137 logger = getLogger('django.request') 138 # Taken from regressiontests/views/views.py: send_log() 139 # ensuring the AdminEmailHandler does not get filtered out 140 # even with DEBUG=True. 141 admin_email_handler = [ 142 h for h in logger.handlers 143 if h.__class__.__name__ == "AdminEmailHandler" 144 ][0] 145 # Backup then override original filters 146 orig_filters = admin_email_handler.filters 147 admin_email_handler.filters = [] 148 149 logger.error(message, token1, token2) 150 151 self.assertEqual(len(mail.outbox), 1) 152 self.assertEqual(mail.outbox[0].to, ['admin@example.com']) 153 self.assertEqual(mail.outbox[0].subject, 154 "[Django] ERROR: This is my message, and it says 'ping' and 'pong'") 155 156 # Restore original filters 157 admin_email_handler.filters = orig_filters