diff options
author | Wolfy-J <[email protected]> | 2019-02-14 14:58:04 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-02-14 14:58:04 +0300 |
commit | a9e8ff6ac4f1a20c2024312cab65dd2c12c721e8 (patch) | |
tree | 3d8641f60a51346dbd044ced080a51e60f61434a /cmd/rr | |
parent | dd4bc086e18cda344b75c29175885db90c8e7196 (diff) |
version bump
Diffstat (limited to 'cmd/rr')
-rw-r--r-- | cmd/rr/cmd/root.go | 30 | ||||
-rw-r--r-- | cmd/rr/main.go | 3 |
2 files changed, 27 insertions, 6 deletions
diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go index ceeeb840..5fa76b87 100644 --- a/cmd/rr/cmd/root.go +++ b/cmd/rr/cmd/root.go @@ -30,8 +30,8 @@ import ( // Service bus for all the commands. var ( - cfgFile string - override []string + cfgFile, workDir, logFormat string + override []string // Verbose enables verbosity mode (container specific). Verbose bool @@ -68,9 +68,12 @@ func Execute() { } func init() { - CLI.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "Verbose output") + CLI.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output") CLI.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "debug mode") + CLI.PersistentFlags().StringVarP(&logFormat, "logFormat", "l", "color", "select log formatter (color, json, plain)") CLI.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is .rr.yaml)") + CLI.PersistentFlags().StringVarP(&workDir, "workDir", "w", "", "work directory") + CLI.PersistentFlags().StringArrayVarP( &override, "override", @@ -84,15 +87,36 @@ func init() { Logger.SetLevel(logrus.DebugLevel) } + configureLogger(logFormat) + cfg, err := util.LoadConfig(cfgFile, []string{"."}, ".rr", override) if err != nil { Logger.Warnf("config: %s", err) return } + if workDir != "" { + if err := os.Chdir(workDir); err != nil { + util.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err) + os.Exit(1) + } + } + if err := Container.Init(cfg); err != nil { util.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err) os.Exit(1) } }) } + +func configureLogger(format string) { + switch format { + case "color", "default": + util.EnableColors = true + Logger.Formatter = &logrus.TextFormatter{ForceColors: true} + case "plain": + Logger.Formatter = &logrus.TextFormatter{DisableColors: true} + case "json": + Logger.Formatter = &logrus.JSONFormatter{} + } +} diff --git a/cmd/rr/main.go b/cmd/rr/main.go index 4d2a06b4..54915957 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -23,7 +23,6 @@ package main import ( - "github.com/sirupsen/logrus" rr "github.com/spiral/roadrunner/cmd/rr/cmd" // services (plugins) @@ -42,8 +41,6 @@ func main() { 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() } |