You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/04/18 09:18:13 UTC
[camel-k] 10/12: Fix #3149: Adds logging to execution of maven commands
This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit e528935d463257ef05fdc95490cb8f61ed79ef72
Author: phantomjinx <p....@phantomjinx.co.uk>
AuthorDate: Tue Mar 29 13:21:14 2022 +0100
Fix #3149: Adds logging to execution of maven commands
* Catches any immediate errors from the command.
---
pkg/util/command.go | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/pkg/util/command.go b/pkg/util/command.go
index 70f9d44e8..196915967 100644
--- a/pkg/util/command.go
+++ b/pkg/util/command.go
@@ -20,6 +20,7 @@ package util
import (
"bufio"
"context"
+ "fmt"
"os/exec"
"golang.org/x/sync/errgroup"
@@ -28,6 +29,8 @@ import (
// RunAndLog starts the provided command, scans its standard and error outputs line by line,
// to feed the provided handlers, and waits until the scans complete and the command returns.
func RunAndLog(ctx context.Context, cmd *exec.Cmd, stdOutF func(string), stdErrF func(string)) (err error) {
+ stdOutF(fmt.Sprintf("Executed command: %s", cmd.String()))
+
stdOut, err := cmd.StdoutPipe()
if err != nil {
return
@@ -38,6 +41,14 @@ func RunAndLog(ctx context.Context, cmd *exec.Cmd, stdOutF func(string), stdErrF
}
err = cmd.Start()
if err != nil {
+ scanOut := bufio.NewScanner(stdOut)
+ for scanOut.Scan() {
+ stdOutF(scanOut.Text())
+ }
+ scanErr := bufio.NewScanner(stdErr)
+ for scanErr.Scan() {
+ stdOutF(scanErr.Text())
+ }
return
}
g, _ := errgroup.WithContext(ctx)