diff --git a/common/logger/logger.go b/common/logger/logger.go index 4a2f07cb30..8519543c6a 100644 --- a/common/logger/logger.go +++ b/common/logger/logger.go @@ -18,6 +18,7 @@ package logger import ( + "flag" "io/ioutil" "log" "os" @@ -64,8 +65,14 @@ func init() { if logger != nil { return } - logConfFile := os.Getenv(constant.APP_LOG_CONF_FILE) - err := InitLog(logConfFile) + + fs := flag.NewFlagSet("log", flag.ContinueOnError) + logConfFile := fs.String("logConf", os.Getenv(constant.APP_LOG_CONF_FILE), "default log config path") + fs.Parse(os.Args[1:]) + for len(fs.Args()) != 0 { + fs.Parse(fs.Args()[1:]) + } + err := InitLog(*logConfFile) if err != nil { log.Printf("[InitLog] warn: %v", err) } diff --git a/config/config_loader.go b/config/config_loader.go index 35910981d1..12f57ee760 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -18,6 +18,7 @@ package config import ( + "flag" "fmt" "log" "os" @@ -63,9 +64,14 @@ func init() { confProFile string ) - confConFile = os.Getenv(constant.CONF_CONSUMER_FILE_PATH) - confProFile = os.Getenv(constant.CONF_PROVIDER_FILE_PATH) - confRouterFile = os.Getenv(constant.CONF_ROUTER_FILE_PATH) + fs := flag.NewFlagSet("config", flag.ContinueOnError) + fs.StringVar(&confConFile, "conConf", os.Getenv(constant.CONF_CONSUMER_FILE_PATH), "default client config path") + fs.StringVar(&confProFile, "proConf", os.Getenv(constant.CONF_PROVIDER_FILE_PATH), "default server config path") + fs.StringVar(&confRouterFile, "rouConf", os.Getenv(constant.CONF_ROUTER_FILE_PATH), "default router config path") + fs.Parse(os.Args[1:]) + for len(fs.Args()) != 0 { + fs.Parse(fs.Args()[1:]) + } if errCon := ConsumerInit(confConFile); errCon != nil { log.Printf("[consumerInit] %#v", errCon)