This repository was archived by the owner on Dec 21, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,11 @@ def format(self, record):
121
121
if "asctime" in self ._required_fields :
122
122
record .asctime = self .formatTime (record , self .datefmt )
123
123
124
+ # Display formatted exception, but allow overriding it in the
125
+ # user-supplied dict.
126
+ if record .exc_info and not message_dict .get ('exc_info' ):
127
+ message_dict ['exc_info' ] = self .formatException (record .exc_info )
128
+
124
129
try :
125
130
log_record = OrderedDict ()
126
131
except NameError :
Original file line number Diff line number Diff line change 2
2
import logging
3
3
import json
4
4
import sys
5
+ import traceback
5
6
6
7
try :
7
8
import xmlrunner
@@ -153,6 +154,22 @@ def process_log_record(self, log_record):
153
154
logJson = json .loads (self .buffer .getvalue ())
154
155
self .assertEqual (logJson .get ("custom" ), "value" )
155
156
157
+ def testExcInfo (self ):
158
+ fr = jsonlogger .JsonFormatter ()
159
+ self .logHandler .setFormatter (fr )
160
+ try :
161
+ raise Exception ('test' )
162
+ except Exception :
163
+
164
+ self .logger .exception ("hello" )
165
+
166
+ expected_value = traceback .format_exc ()
167
+ # Formatter removes trailing new line
168
+ if expected_value .endswith ('\n ' ):
169
+ expected_value = expected_value [:- 1 ]
170
+
171
+ logJson = json .loads (self .buffer .getvalue ())
172
+ self .assertEqual (logJson .get ("exc_info" ), expected_value )
156
173
157
174
if __name__ == '__main__' :
158
175
if len (sys .argv [1 :]) > 0 :
You can’t perform that action at this time.
0 commit comments