@@ -369,15 +369,31 @@ def _logs(pod_name: str, follow: bool):
369
369
return # cancelled by user
370
370
371
371
try :
372
- stream = pod_log (pod_name , container_name = None , follow = follow )
373
- for line in stream . stream ( ):
374
- print ( line . decode ( "utf-8" ), end = None )
372
+ stream = pod_log (pod_name , container_name = None , follow = follow , namespace = pod_namespace )
373
+ for line in iter_lines_from_stream ( stream ):
374
+ click . secho ( line )
375
375
except Exception as e :
376
376
print (e )
377
377
except KeyboardInterrupt :
378
378
print ("Interrupted streaming log!" )
379
379
380
380
381
+ def iter_lines_from_stream (log_stream , encoding = "utf-8" ):
382
+ decoder = codecs .getincrementaldecoder (encoding )()
383
+ buffer = ""
384
+ for chunk in log_stream .stream ():
385
+ # Decode the chunk incrementally
386
+ text = decoder .decode (chunk )
387
+ buffer += text
388
+ # Split the buffer into lines
389
+ lines = buffer .split ("\n " )
390
+ buffer = lines .pop () # Last item is incomplete line or empty
391
+ yield from lines
392
+ # Yield any remaining text in the buffer
393
+ if buffer :
394
+ yield buffer
395
+
396
+
381
397
@click .command ()
382
398
@click .argument ("tank_name" , required = False )
383
399
@click .option ("--all" , "-a" , "snapshot_all" , is_flag = True , help = "Snapshot all running tanks" )
0 commit comments