@@ -155,6 +155,8 @@ def __init__(
155155 reserved_attrs : Optional [Sequence [str ]] = None ,
156156 timestamp : Union [bool , str ] = False ,
157157 defaults : Optional [Dict [str , Any ]] = None ,
158+ exc_info_as_array : bool = False ,
159+ stack_info_as_array : bool = False ,
158160 ) -> None :
159161 """
160162 Args:
@@ -177,6 +179,8 @@ def __init__(
177179 outputting the json log record. If string is passed, timestamp will be added
178180 to log record using string as key. If True boolean is passed, timestamp key
179181 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.
180184
181185 *Changed in 3.1*:
182186
@@ -219,6 +223,8 @@ def __init__(
219223 self ._skip_fields = set (self ._required_fields )
220224 self ._skip_fields .update (self .reserved_attrs )
221225 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
222228 return
223229
224230 def format (self , record : logging .LogRecord ) -> str :
@@ -247,11 +253,17 @@ def format(self, record: logging.LogRecord) -> str:
247253 if not message_dict .get ("exc_info" ) and record .exc_text :
248254 message_dict ["exc_info" ] = record .exc_text
249255
256+ if self .exc_info_as_array and message_dict .get ("exc_info" ):
257+ message_dict ["exc_info" ] = message_dict ["exc_info" ].splitlines ()
258+
250259 # Display formatted record of stack frames
251260 # default format is a string returned from :func:`traceback.print_stack`
252261 if record .stack_info and not message_dict .get ("stack_info" ):
253262 message_dict ["stack_info" ] = self .formatStack (record .stack_info )
254263
264+ if self .stack_info_as_array and message_dict .get ("stack_info" ):
265+ message_dict ["stack_info" ] = message_dict ["stack_info" ].splitlines ()
266+
255267 log_record : LogRecord = {}
256268 self .add_fields (log_record , record , message_dict )
257269 log_record = self .process_log_record (log_record )
0 commit comments