mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 20:52:14 +01:00
better logical operation for xexec command output
This commit is contained in:
@@ -2,6 +2,7 @@ package xexec
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -75,13 +76,12 @@ func pipe(logger xlog.Logger, cmd *exec.Cmd) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func logCommandOutput(logger xlog.Logger, reader io.ReadCloser, outputType string, cmd *exec.Cmd) {
|
func logCommandOutput(logger xlog.Logger, reader io.ReadCloser, outputType string, cmd *exec.Cmd) {
|
||||||
var op string
|
var buf bytes.Buffer
|
||||||
if len(cmd.Args) >= 2 {
|
buf.WriteString(fmt.Sprintf("%s", outputType))
|
||||||
op = fmt.Sprintf("%s.%s.%s", cmd.Args[0], cmd.Args[1], outputType)
|
for _, arg := range cmd.Args {
|
||||||
} else {
|
buf.WriteString(fmt.Sprintf(".%s", arg))
|
||||||
// len(cmd.Args) should always be >= 1.
|
|
||||||
op = fmt.Sprintf("%s.%s", cmd.Args[0], outputType)
|
|
||||||
}
|
}
|
||||||
|
op := buf.String()
|
||||||
r := bufio.NewReader(reader)
|
r := bufio.NewReader(reader)
|
||||||
defer reader.Close() // nolint: errcheck
|
defer reader.Close() // nolint: errcheck
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func TestCommandContext(t *testing.T) {
|
|||||||
logger := xlogtest.DebugLogger()
|
logger := xlogtest.DebugLogger()
|
||||||
// should pipe command output as
|
// should pipe command output as
|
||||||
// xlog.Logger has a xlog.DebugLevel.
|
// xlog.Logger has a xlog.DebugLevel.
|
||||||
cmd, err := CommandContext(context.Background(), logger, "echo")
|
cmd, err := CommandContext(context.Background(), logger, "echo", "Hello", "World")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
LogBeforeExecute(logger, cmd)
|
LogBeforeExecute(logger, cmd)
|
||||||
// should not pipe command output as
|
// should not pipe command output as
|
||||||
|
|||||||
Reference in New Issue
Block a user