@@ -246,7 +246,7 @@ def finish_launch(self, end_time, status=None, attributes=None, **kwargs):
246246 """
247247 # process log batches firstly:
248248 if self ._batch_logs :
249- self .log_batch ([] , force = True )
249+ self ._log_batch ( None , force = True )
250250 if attributes and isinstance (attributes , dict ):
251251 attributes = _dict_to_payload (attributes )
252252 data = {
@@ -463,14 +463,14 @@ def log(self, time, message, level=None, attachment=None, item_id=None):
463463 data ["itemUuid" ] = item_id
464464 if attachment :
465465 data ["attachment" ] = attachment
466- return self .log_batch ([ data ], item_id = item_id )
466+ return self ._log_batch ( data )
467467
468- def log_batch (self , log_data , item_id = None , force = False ):
468+ def _log_batch (self , log_data , force = False ):
469469 """
470470 Log batch of messages with attachment.
471471
472472 Args:
473- log_data: list of log records .
473+ log_data: log record that needs to be processed .
474474 log record is a dict of;
475475 time, message, level, attachment
476476 attachment is a dict of:
@@ -481,21 +481,17 @@ def log_batch(self, log_data, item_id=None, force=False):
481481 force: Flag that forces client to process all the logs
482482 stored in self._batch_logs immediately
483483 """
484- self ._batch_logs += log_data
484+ if log_data :
485+ self ._batch_logs .append (log_data )
486+
485487 if len (self ._batch_logs ) < self .log_batch_size and not force :
486488 return
487- url = uri_join (self .base_url_v2 , "log" )
488489
490+ url = uri_join (self .base_url_v2 , "log" )
489491 attachments = []
490492 for log_item in self ._batch_logs :
491- if item_id :
492- log_item ["itemUuid" ] = item_id
493493 log_item ["launchUuid" ] = self .launch_id
494- attachment = log_item .get ("attachment" , None )
495-
496- if "attachment" in log_item :
497- del log_item ["attachment" ]
498-
494+ attachment = log_item .pop ("attachment" , None )
499495 if attachment :
500496 if not isinstance (attachment , Mapping ):
501497 attachment = {"data" : attachment }
@@ -523,12 +519,9 @@ def log_batch(self, log_data, item_id=None, force=False):
523519 files = files ,
524520 verify = self .verify_ssl
525521 )
526- logger .debug ("log_batch - ID: %s" , item_id )
527522 logger .debug ("log_batch response: %s" , r .text )
528523 self ._batch_logs = []
529524 return _get_data (r )
530525 except KeyError :
531- if i < POST_LOGBATCH_RETRY_COUNT - 1 :
532- continue
533- else :
526+ if i + 1 == POST_LOGBATCH_RETRY_COUNT :
534527 raise
0 commit comments