@@ -1176,24 +1176,39 @@ def enqueue(self, record):
11761176 """
11771177 self .queue .put_nowait (record )
11781178
1179+ def prepare (self , record ):
1180+ """
1181+ Prepares a record for queuing. The object returned by this
1182+ method is enqueued.
1183+
1184+ The base implementation formats the record to merge the message
1185+ and arguments, and removes unpickleable items from the record
1186+ in-place.
1187+
1188+ You might want to override this method if you want to convert
1189+ the record to a dict or JSON string, or send a modified copy
1190+ of the record while leaving the original intact.
1191+ """
1192+ # The format operation gets traceback text into record.exc_text
1193+ # (if there's exception data), and also puts the message into
1194+ # record.message. We can then use this to replace the original
1195+ # msg + args, as these might be unpickleable. We also zap the
1196+ # exc_info attribute, as it's no longer needed and, if not None,
1197+ # will typically not be pickleable.
1198+ self .format (record )
1199+ record .msg = record .message
1200+ record .args = None
1201+ record .exc_info = None
1202+ return record
1203+
11791204 def emit (self , record ):
11801205 """
11811206 Emit a record.
11821207
1183- Writes the LogRecord to the queue, preparing it for pickling first.
1208+ Writes the LogRecord to the queue, preparing it first.
11841209 """
11851210 try :
1186- # The format operation gets traceback text into record.exc_text
1187- # (if there's exception data), and also puts the message into
1188- # record.message. We can then use this to replace the original
1189- # msg + args, as these might be unpickleable. We also zap the
1190- # exc_info attribute, as it's no longer needed and, if not None,
1191- # will typically not be pickleable.
1192- self .format (record )
1193- record .msg = record .message
1194- record .args = None
1195- record .exc_info = None
1196- self .enqueue (record )
1211+ self .enqueue (self .prepare (record ))
11971212 except (KeyboardInterrupt , SystemExit ):
11981213 raise
11991214 except :
0 commit comments