Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: read configuration path from the command line when start #1039

Merged
merged 3 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package logger

import (
"flag"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 9 additions & 3 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package config

import (
"flag"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -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)
Expand Down