From 5a33d13de098840002f06dedf25e5a1e532a001b Mon Sep 17 00:00:00 2001 From: stirante Date: Sat, 25 Sep 2021 20:13:49 +0200 Subject: [PATCH] Send filter output through logs --- regolith/utils.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/regolith/utils.go b/regolith/utils.go index 0ab3cdbc..916dabb7 100644 --- a/regolith/utils.go +++ b/regolith/utils.go @@ -1,8 +1,10 @@ package regolith import ( + "bufio" "errors" "fmt" + "io" "os" "os/exec" "path/filepath" @@ -32,9 +34,18 @@ func GetAbsoluteWorkingDirectory() string { func RunSubProcess(command string, args []string, absoluteLocation string, workingDir string) error { cmd := exec.Command(command, args...) cmd.Dir = workingDir - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr + out, _ := cmd.StdoutPipe() + err, _ := cmd.StderrPipe() + go LogStd(out, Logger.Infof) + go LogStd(err, Logger.Errorf) cmd.Env = append(os.Environ(), "FILTER_DIR="+absoluteLocation) return cmd.Run() } + +func LogStd(in io.ReadCloser, logFunc func(template string, args ...interface{})) { + scanner := bufio.NewScanner(in) + for scanner.Scan() { + logFunc("[Filter] %s", scanner.Text()) + } +}