@@ -246,7 +246,7 @@ def finish_launch(self, end_time, status=None, attributes=None, **kwargs):
246
246
"""
247
247
# process log batches firstly:
248
248
if self ._batch_logs :
249
- self .log_batch ([] , force = True )
249
+ self ._log_batch ( None , force = True )
250
250
if attributes and isinstance (attributes , dict ):
251
251
attributes = _dict_to_payload (attributes )
252
252
data = {
@@ -463,14 +463,14 @@ def log(self, time, message, level=None, attachment=None, item_id=None):
463
463
data ["itemUuid" ] = item_id
464
464
if attachment :
465
465
data ["attachment" ] = attachment
466
- return self .log_batch ([ data ], item_id = item_id )
466
+ return self ._log_batch ( data )
467
467
468
- def log_batch (self , log_data , item_id = None , force = False ):
468
+ def _log_batch (self , log_data , force = False ):
469
469
"""
470
470
Log batch of messages with attachment.
471
471
472
472
Args:
473
- log_data: list of log records .
473
+ log_data: log record that needs to be processed .
474
474
log record is a dict of;
475
475
time, message, level, attachment
476
476
attachment is a dict of:
@@ -481,21 +481,17 @@ def log_batch(self, log_data, item_id=None, force=False):
481
481
force: Flag that forces client to process all the logs
482
482
stored in self._batch_logs immediately
483
483
"""
484
- self ._batch_logs += log_data
484
+ if log_data :
485
+ self ._batch_logs .append (log_data )
486
+
485
487
if len (self ._batch_logs ) < self .log_batch_size and not force :
486
488
return
487
- url = uri_join (self .base_url_v2 , "log" )
488
489
490
+ url = uri_join (self .base_url_v2 , "log" )
489
491
attachments = []
490
492
for log_item in self ._batch_logs :
491
- if item_id :
492
- log_item ["itemUuid" ] = item_id
493
493
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 )
499
495
if attachment :
500
496
if not isinstance (attachment , Mapping ):
501
497
attachment = {"data" : attachment }
@@ -523,12 +519,9 @@ def log_batch(self, log_data, item_id=None, force=False):
523
519
files = files ,
524
520
verify = self .verify_ssl
525
521
)
526
- logger .debug ("log_batch - ID: %s" , item_id )
527
522
logger .debug ("log_batch response: %s" , r .text )
528
523
self ._batch_logs = []
529
524
return _get_data (r )
530
525
except KeyError :
531
- if i < POST_LOGBATCH_RETRY_COUNT - 1 :
532
- continue
533
- else :
526
+ if i + 1 == POST_LOGBATCH_RETRY_COUNT :
534
527
raise
0 commit comments