@@ -7,40 +7,57 @@ import (
77 "github.com/spf13/cobra"
88)
99
10- var (
11- logLevel string
12- )
10+ type Logging struct {
11+ Command * cobra. Command
12+ }
1313
14- type SetLogLevelController struct {
15- ServiceName string
14+ func (r * Registry ) Logging () * Logging {
15+ cmd := & cobra.Command {
16+ Use : "log" ,
17+ Short : "Logging related commands" ,
18+ }
19+ cmd .AddCommand (r .BuildSetLogLevelCommand ())
20+ return & Logging {
21+ Command : cmd ,
22+ }
1623}
1724
18- func BuildSetLogLevelCommand (rootCmd * cobra.Command ) {
25+ // log level
26+
27+ var (
28+ desiredLogLevel string
29+ )
30+
31+ func (r * Registry ) BuildSetLogLevelCommand () * cobra.Command {
1932 cmd := & cobra.Command {
20- Use : "log level" ,
33+ Use : "level" ,
2134 Short : "Set Envoy log level" ,
2235 Long : `Set the Envoy sidecar log level` ,
23- Args : cobra .MinimumNArgs (2 ),
36+ Args : cobra .MinimumNArgs (1 ),
2437 RunE : func (cmd * cobra.Command , args []string ) error {
2538 controller := SetLogLevelController {
26- ServiceName : args [1 ],
39+ ServiceName : args [0 ],
2740 }
2841 return controller .Run ()
2942 },
3043 }
31- cmd .Flags ().StringVarP (& logLevel , "level" , "l" , "" , "Desired log level (debug/info/warning/error" )
32- rootCmd .AddCommand (cmd )
44+ cmd .Flags ().StringVarP (& desiredLogLevel , "level" , "l" , "" , "Desired log level (debug/info/warning/error" )
45+ return cmd
46+ }
47+
48+ type SetLogLevelController struct {
49+ ServiceName string
3350}
3451
3552func (c * SetLogLevelController ) Run () error {
36- if logLevel == "" {
37- logLevel = c .SelectLogLevel ()
53+ if desiredLogLevel == "" {
54+ desiredLogLevel = c .SelectLogLevel ()
3855 }
3956 e , err := envoy .NewFromServiceName (c .ServiceName )
4057 if err != nil {
4158 return err
4259 }
43- e .Logging ().SetLevel (logLevel )
60+ e .Logging ().SetLevel (desiredLogLevel )
4461 return nil
4562}
4663
0 commit comments