@@ -155,6 +155,8 @@ def __init__(
155
155
reserved_attrs : Optional [Sequence [str ]] = None ,
156
156
timestamp : Union [bool , str ] = False ,
157
157
defaults : Optional [Dict [str , Any ]] = None ,
158
+ exc_info_as_array : bool = False ,
159
+ stack_info_as_array : bool = False ,
158
160
) -> None :
159
161
"""
160
162
Args:
@@ -177,6 +179,8 @@ def __init__(
177
179
outputting the json log record. If string is passed, timestamp will be added
178
180
to log record using string as key. If True boolean is passed, timestamp key
179
181
will be "timestamp". Defaults to False/off.
182
+ exc_info_as_array: break the exc_info into a list of lines based on line breaks.
183
+ stack_info_as_array: break the stack_info into a list of lines based on line breaks.
180
184
181
185
*Changed in 3.1*:
182
186
@@ -219,6 +223,8 @@ def __init__(
219
223
self ._skip_fields = set (self ._required_fields )
220
224
self ._skip_fields .update (self .reserved_attrs )
221
225
self .defaults = defaults if defaults is not None else {}
226
+ self .exc_info_as_array = exc_info_as_array
227
+ self .stack_info_as_array = stack_info_as_array
222
228
return
223
229
224
230
def format (self , record : logging .LogRecord ) -> str :
@@ -247,11 +253,17 @@ def format(self, record: logging.LogRecord) -> str:
247
253
if not message_dict .get ("exc_info" ) and record .exc_text :
248
254
message_dict ["exc_info" ] = record .exc_text
249
255
256
+ if self .exc_info_as_array and message_dict .get ("exc_info" ):
257
+ message_dict ["exc_info" ] = message_dict ["exc_info" ].splitlines ()
258
+
250
259
# Display formatted record of stack frames
251
260
# default format is a string returned from :func:`traceback.print_stack`
252
261
if record .stack_info and not message_dict .get ("stack_info" ):
253
262
message_dict ["stack_info" ] = self .formatStack (record .stack_info )
254
263
264
+ if self .stack_info_as_array and message_dict .get ("stack_info" ):
265
+ message_dict ["stack_info" ] = message_dict ["stack_info" ].splitlines ()
266
+
255
267
log_record : LogRecord = {}
256
268
self .add_fields (log_record , record , message_dict )
257
269
log_record = self .process_log_record (log_record )
0 commit comments