From a9e8ff6ac4f1a20c2024312cab65dd2c12c721e8 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Thu, 14 Feb 2019 14:58:04 +0300 Subject: version bump --- cmd/rr/cmd/root.go | 30 +++++++++++++++++++++++++++--- cmd/rr/main.go | 3 --- 2 files changed, 27 insertions(+), 6 deletions(-) (limited to 'cmd/rr') 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("Error: %s\n", err) + os.Exit(1) + } + } + if err := Container.Init(cfg); err != nil { util.Printf("Error: %s\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() } -- cgit v1.2.3