@@ -431,7 +431,7 @@ func main() {
431
431
case cleanupCmd .FullCommand ():
432
432
out , err = doCleanup (ctx , conn , pbm , & cleanupOpts )
433
433
case logsCmd .FullCommand ():
434
- out , err = runLogs (ctx , conn , & logs )
434
+ out , err = runLogs (ctx , conn , & logs , pbmOutF )
435
435
case statusCmd .FullCommand ():
436
436
out , err = status (ctx , conn , pbm , * mURL , statusOpts , pbmOutF == outJSONpretty )
437
437
case describeRestoreCmd .FullCommand ():
@@ -496,7 +496,7 @@ func exitErr(e error, f outFormat) {
496
496
os .Exit (1 )
497
497
}
498
498
499
- func runLogs (ctx context.Context , conn connect.Client , l * logsOpts ) (fmt.Stringer , error ) {
499
+ func runLogs (ctx context.Context , conn connect.Client , l * logsOpts , f outFormat ) (fmt.Stringer , error ) {
500
500
r := & log.LogRequest {}
501
501
502
502
if l .node != "" {
@@ -535,7 +535,7 @@ func runLogs(ctx context.Context, conn connect.Client, l *logsOpts) (fmt.Stringe
535
535
}
536
536
537
537
if l .follow {
538
- err := followLogs (ctx , conn , r , r .Node == "" , l .extr )
538
+ err := followLogs (ctx , conn , r , r .Node == "" , l .extr , f )
539
539
return nil , err
540
540
}
541
541
@@ -561,17 +561,32 @@ func runLogs(ctx context.Context, conn connect.Client, l *logsOpts) (fmt.Stringe
561
561
return o , nil
562
562
}
563
563
564
- func followLogs (ctx context.Context , conn connect.Client , r * log.LogRequest , showNode , expr bool ) error {
564
+ func followLogs (ctx context.Context , conn connect.Client , r * log.LogRequest , showNode , expr bool , f outFormat ) error {
565
565
outC , errC := log .Follow (ctx , conn , r , false )
566
566
567
+ var enc * json.Encoder
568
+ if f == outJSON {
569
+ enc = json .NewEncoder (os .Stdout )
570
+ } else if f == outJSONpretty {
571
+ enc = json .NewEncoder (os .Stdout )
572
+ enc .SetIndent ("" , " " )
573
+ }
574
+
567
575
for {
568
576
select {
569
577
case entry , ok := <- outC :
570
578
if ! ok {
571
579
return nil
572
580
}
573
581
574
- fmt .Println (entry .Stringify (tsUTC , showNode , expr ))
582
+ if f == outJSON || f == outJSONpretty {
583
+ err := enc .Encode (entry )
584
+ if err != nil {
585
+ exitErr (errors .Wrap (err , "encode output" ), f )
586
+ }
587
+ } else {
588
+ fmt .Println (entry .Stringify (tsUTC , showNode , expr ))
589
+ }
575
590
case err , ok := <- errC :
576
591
if ! ok {
577
592
return nil
0 commit comments