@@ -435,15 +435,13 @@ func (p *GCloud) PrintInstanceLogs(ctx *lepton.Context, instancename string, wat
435435 if watch {
436436 line := int64 (0 )
437437 for {
438-
439438 l , last , err := p .getLogs (ctx , instancename , line )
440439 if err != nil {
441440 fmt .Println (err )
441+ } else {
442+ line = last
443+ fmt .Printf (l )
442444 }
443-
444- line = last
445-
446- fmt .Printf (l )
447445 time .Sleep (1 * time .Second )
448446 }
449447 }
@@ -464,17 +462,10 @@ func (p *GCloud) GetInstanceLogs(ctx *lepton.Context, instancename string) (stri
464462
465463func (p * GCloud ) getLogs (ctx * lepton.Context , instancename string , start int64 ) (string , int64 , error ) {
466464 context := context .TODO ()
467-
468465 cloudConfig := ctx .Config ().CloudConfig
469- lastPos := start
470-
471- resp , err := p .Service .Instances .GetSerialPortOutput (cloudConfig .ProjectID , cloudConfig .Zone , instancename ).Start (lastPos ).Context (context ).Do ()
466+ resp , err := p .Service .Instances .GetSerialPortOutput (cloudConfig .ProjectID , cloudConfig .Zone , instancename ).Start (start ).Context (context ).Do ()
472467 if err != nil {
473- return "" , resp .Next , err
474- }
475- if resp .Contents != "" {
476- return resp .Contents , resp .Next , nil
468+ return "" , start , err
477469 }
478-
479- return "" , resp .Next , nil
470+ return resp .Contents , resp .Next , nil
480471}
0 commit comments