Skip to content

Commit

Permalink
✨ adding ability to handle logs from binary (#313)
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley authored Sep 14, 2023
1 parent ab5343b commit 3b2a541
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions provider/grpc/provider.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package grpc

import (
"bufio"
"context"
"fmt"
"io"
"log"
"os/exec"
"time"
Expand Down Expand Up @@ -32,6 +34,7 @@ var _ provider.InternalProviderClient = &grpcProvider{}
var _ provider.Startable = &grpcProvider{}

func NewGRPCClient(config provider.Config, log logr.Logger) *grpcProvider {
log = log.WithName(config.Name)
log = log.WithValues("provider", "grpc")
return &grpcProvider{
config: config,
Expand Down Expand Up @@ -134,6 +137,12 @@ func (g *grpcProvider) Start(ctx context.Context) error {
cmd := exec.CommandContext(ctx, g.config.BinaryPath, "--port", fmt.Sprintf("%v", port))
// TODO: For each output line, log that line here, allows the server's to output to the main log file. Make sure we name this correctly
// cmd will exit with the ending of the ctx.
out, err := cmd.StdoutPipe()
if err != nil {
return err
}
go g.LogProviderOut(ctx, out)

err = cmd.Start()
if err != nil {
return err
Expand Down Expand Up @@ -174,3 +183,11 @@ func (g *grpcProvider) Start(ctx context.Context) error {
}
return fmt.Errorf("must set Address or Binary Path for a GRPC provider")
}

func (g *grpcProvider) LogProviderOut(ctx context.Context, out io.ReadCloser) {
scan := bufio.NewScanner(out)

for scan.Scan() {
g.log.V(3).Info(scan.Text())
}
}

0 comments on commit 3b2a541

Please sign in to comment.