@@ -36,6 +36,7 @@ import (
36
36
srv_debug "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
37
37
srv_monitor "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/monitor/v1"
38
38
srv_settings "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
39
+ "github.com/arduino/go-paths-helper"
39
40
"github.com/segmentio/stats/v4"
40
41
"github.com/sirupsen/logrus"
41
42
"github.com/spf13/cobra"
47
48
ip string
48
49
daemonize bool
49
50
debug bool
51
+ debugFile string
50
52
debugFilters []string
51
53
)
52
54
@@ -65,6 +67,7 @@ func NewCommand() *cobra.Command {
65
67
configuration .Settings .BindPFlag ("daemon.port" , daemonCommand .PersistentFlags ().Lookup ("port" ))
66
68
daemonCommand .Flags ().BoolVar (& daemonize , "daemonize" , false , tr ("Do not terminate daemon process if the parent process dies" ))
67
69
daemonCommand .Flags ().BoolVar (& debug , "debug" , false , tr ("Enable debug logging of gRPC calls" ))
70
+ daemonCommand .Flags ().StringVar (& debugFile , "debug-file" , "" , tr ("Append debug logging to the specified file" ))
68
71
daemonCommand .Flags ().StringSliceVar (& debugFilters , "debug-filter" , []string {}, tr ("Display only the provided gRPC calls" ))
69
72
return daemonCommand
70
73
}
@@ -79,7 +82,23 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
79
82
}
80
83
port := configuration .Settings .GetString ("daemon.port" )
81
84
gRPCOptions := []grpc.ServerOption {}
85
+ if debugFile != "" {
86
+ if ! debug {
87
+ feedback .Error (tr ("The flag --debug-file must be used with --debug." ))
88
+ os .Exit (errorcodes .ErrBadArgument )
89
+ }
90
+ }
82
91
if debug {
92
+ if debugFile != "" {
93
+ outFile := paths .New (debugFile )
94
+ f , err := outFile .Append ()
95
+ if err != nil {
96
+ feedback .Error (tr ("Error opening debug logging file: %s" , err ))
97
+ os .Exit (errorcodes .ErrBadCall )
98
+ }
99
+ debugStdOut = f
100
+ defer f .Close ()
101
+ }
83
102
gRPCOptions = append (gRPCOptions ,
84
103
grpc .UnaryInterceptor (unaryLoggerInterceptor ),
85
104
grpc .StreamInterceptor (streamLoggerInterceptor ),
0 commit comments