mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-13 10:52:15 +01:00
better logical operation for xexec command output
This commit is contained in:
@@ -2,6 +2,7 @@ package xexec
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"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) {
|
||||
var op string
|
||||
if len(cmd.Args) >= 2 {
|
||||
op = fmt.Sprintf("%s.%s.%s", cmd.Args[0], cmd.Args[1], outputType)
|
||||
} else {
|
||||
// len(cmd.Args) should always be >= 1.
|
||||
op = fmt.Sprintf("%s.%s", cmd.Args[0], outputType)
|
||||
var buf bytes.Buffer
|
||||
buf.WriteString(fmt.Sprintf("%s", outputType))
|
||||
for _, arg := range cmd.Args {
|
||||
buf.WriteString(fmt.Sprintf(".%s", arg))
|
||||
}
|
||||
op := buf.String()
|
||||
r := bufio.NewReader(reader)
|
||||
defer reader.Close() // nolint: errcheck
|
||||
for {
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestCommandContext(t *testing.T) {
|
||||
logger := xlogtest.DebugLogger()
|
||||
// should pipe command output as
|
||||
// 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)
|
||||
LogBeforeExecute(logger, cmd)
|
||||
// should not pipe command output as
|
||||
|
||||
Reference in New Issue
Block a user