Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ adding ability to handle logs from binary #313

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
}
}