Skip to content

Commit 6476ae2

Browse files
committed
Removed direct access to stdio streams in daemon command
1 parent 3526d60 commit 6476ae2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cli/daemon/daemon.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,15 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
8989
if err != nil {
9090
feedback.Fatal(tr("Error opening debug logging file: %s", err), errorcodes.ErrBadCall)
9191
}
92-
debugStdOut = f
9392
defer f.Close()
93+
debugStdOut = f
94+
} else {
95+
// Attach to os.Stdout only if we are in Text mode
96+
if feedback.GetFormat() != feedback.Text {
97+
feedback.Fatal(tr("Debug log is only available in text format"), errorcodes.ErrBadArgument)
98+
}
99+
out, _, _ := feedback.OutputStreams()
100+
debugStdOut = out
94101
}
95102
gRPCOptions = append(gRPCOptions,
96103
grpc.UnaryInterceptor(unaryLoggerInterceptor),

cli/daemon/interceptors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import (
1919
"context"
2020
"encoding/json"
2121
"fmt"
22-
"os"
22+
"io"
2323
"strings"
2424
"sync/atomic"
2525

2626
"google.golang.org/grpc"
2727
)
2828

29-
var debugStdOut = os.Stdout
29+
var debugStdOut io.Writer
3030
var debugSeq uint32
3131

3232
func log(isRequest bool, seq uint32, msg interface{}) {

0 commit comments

Comments
 (0)