diff options
author | Wolfy-J <[email protected]> | 2018-09-07 23:37:28 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-09-07 23:37:28 +0300 |
commit | 4dea95a525707af1a726e9af024e4abdbde28820 (patch) | |
tree | 14a8f49a93a48c1fba3d8e080ebc0b71301473c9 /cmd | |
parent | f0bc4fc0da3a00cee746535bd9817f31e97bcb0d (diff) |
improved debug handlers (moved from common package)
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/rr/cmd/root.go | 36 | ||||
-rw-r--r-- | cmd/rr/http/debug.go | 19 | ||||
-rw-r--r-- | cmd/rr/main.go | 11 |
3 files changed, 40 insertions, 26 deletions
diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go index 595395c0..5e936580 100644 --- a/cmd/rr/cmd/root.go +++ b/cmd/rr/cmd/root.go @@ -24,17 +24,20 @@ import ( "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/spiral/roadrunner/cmd/rr/debug" "github.com/spiral/roadrunner/cmd/rr/utils" "github.com/spiral/roadrunner/service" - "github.com/spiral/roadrunner/service/http" "os" ) // Service bus for all the commands. var ( - cfgFile string - verbose, debugMode bool + cfgFile string + + // Verbose enables verbosity mode (container specific). + Verbose bool + + // Debug enables debug mode (service specific). + Debug bool // Logger - shared logger. Logger = logrus.New() @@ -78,6 +81,13 @@ func (w *ViperWrapper) Unmarshal(out interface{}) error { // Execute adds all child commands to the CLI command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the CLI. func Execute() { + if cfg := initConfig(cfgFile, []string{"."}, ".rr"); cfg != nil { + if err := Container.Init(cfg); err != nil { + utils.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err) + os.Exit(1) + } + } + if err := CLI.Execute(); err != nil { utils.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err) os.Exit(1) @@ -85,26 +95,14 @@ func Execute() { } func init() { - CLI.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output") - CLI.PersistentFlags().BoolVarP(&debugMode, "debug", "d", false, "debug mode") + CLI.PersistentFlags().BoolVarP(&Verbose, "Verbose", "v", false, "Verbose output") + CLI.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "debug mode") CLI.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is .rr.yaml)") cobra.OnInitialize(func() { - if verbose { + if Verbose { Logger.SetLevel(logrus.DebugLevel) } - - if debugMode { - svc, _ := Container.Get(http.ID) - svc.(*http.Service).AddListener(debug.Listener(Logger)) - } - - if cfg := initConfig(cfgFile, []string{"."}, ".rr"); cfg != nil { - if err := Container.Init(cfg); err != nil { - utils.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err) - os.Exit(1) - } - } }) } diff --git a/cmd/rr/http/debug.go b/cmd/rr/http/debug.go index d02cfda6..cae10452 100644 --- a/cmd/rr/http/debug.go +++ b/cmd/rr/http/debug.go @@ -1 +1,20 @@ package http + +import ( + rr "github.com/spiral/roadrunner/cmd/rr/cmd" + + "github.com/spf13/cobra" + "github.com/spiral/roadrunner/service/http" + "github.com/spiral/roadrunner/cmd/rr/debug" +) + +func init(){ + cobra.OnInitialize(func() { + if rr.Debug { + svc, _ := rr.Container.Get(http.ID) + if svc, ok := svc.(*http.Service); ok { + svc.AddListener(debug.Listener(rr.Logger)) + } + } + }) +}
\ No newline at end of file diff --git a/cmd/rr/main.go b/cmd/rr/main.go index 01a5aaf3..c4eac19b 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -23,9 +23,6 @@ package main import ( - // colorful logging - "github.com/sirupsen/logrus" - rr "github.com/spiral/roadrunner/cmd/rr/cmd" // services (plugins) @@ -36,17 +33,17 @@ import ( // additional command handlers _ "github.com/spiral/roadrunner/cmd/rr/http" + "github.com/sirupsen/logrus" ) func main() { - rr.Logger.Formatter = &logrus.TextFormatter{ForceColors: true} - - rr.Container.Register(env.ID, env.NewService(map[string]string{"rr": rr.Version})) - + rr.Container.Register(env.ID, &env.Service{}) rr.Container.Register(rpc.ID, &rpc.Service{}) rr.Container.Register(http.ID, &http.Service{}) rr.Container.Register(static.ID, &static.Service{}) + rr.Logger.Formatter = &logrus.TextFormatter{ForceColors: true} + // you can register additional commands using cmd.CLI rr.Execute() } |