summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-12-07 15:58:35 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-12-07 15:58:35 +0100
commitf48c7c3164b0568de45d7ccc88b0ce7724a17cc4 (patch)
tree0927a1c1cca465443b5880005b2c7bc7542c9047 /main.go
parent721497790c39e6f63d96c74d53d0c2bc9549df2f (diff)
Display early log when exiting earlier.
Diffstat (limited to 'main.go')
-rw-r--r--main.go25
1 files changed, 19 insertions, 6 deletions
diff --git a/main.go b/main.go
index 0908140..c8effe6 100644
--- a/main.go
+++ b/main.go
@@ -75,14 +75,28 @@ var IOsk *socketio_client.Client
// exitError exists this program with the specified error
func exitError(code int, f string, a ...interface{}) {
+ earlyDisplay()
err := fmt.Sprintf(f, a...)
fmt.Fprintf(os.Stderr, err+"\n")
os.Exit(code)
}
+// earlyDebug Used to log info before logger has been initialized
+var earlyDebug []string
+
+func earlyPrintf(format string, args ...interface{}) {
+ earlyDebug = append(earlyDebug, fmt.Sprintf(format, args...))
+}
+
+func earlyDisplay() {
+ for _, str := range earlyDebug {
+ Log.Infof("%s", str)
+ }
+ earlyDebug = []string{}
+}
+
// main
func main() {
- var earlyDebug []string
// Allow to set app name from cli (useful for debugging)
if AppName == "" {
@@ -217,7 +231,7 @@ func main() {
// Load config file if requested
if confFile != "" {
- earlyDebug = append(earlyDebug, fmt.Sprintf("confFile detected: %v", confFile))
+ earlyPrintf("confFile detected: %v", confFile)
if !common.Exists(confFile) {
exitError(1, "Error env config file not found")
}
@@ -232,7 +246,7 @@ func main() {
if err != nil {
exitError(1, "Error reading env config file "+confFile)
}
- earlyDebug = append(earlyDebug, fmt.Sprintf("EnvConfFileMap: %v", EnvConfFileMap))
+ earlyPrintf("EnvConfFileMap: %v", EnvConfFileMap)
}
app.Before = func(ctx *cli.Context) error {
@@ -258,9 +272,7 @@ func main() {
Log.Formatter = &logrus.TextFormatter{}
Log.Infof("%s version: %s", AppName, app.Version)
- for _, str := range earlyDebug {
- Log.Infof("%s", str)
- }
+ earlyDisplay()
Log.Debugf("\nEnvironment: %v\n", os.Environ())
if err = XdsConnInit(ctx); err != nil {
@@ -361,6 +373,7 @@ func XdsConnInit(ctx *cli.Context) error {
}
svrCfg := xdsConf.Servers[XdsServerIndexGet()]
if (serverURL != "" && svrCfg.URL != serverURL) || !svrCfg.Connected {
+ Log.Infof("Update XDS Server config: serverURL=%v, svrCfg=%v", serverURL, svrCfg)
if serverURL != "" {
svrCfg.URL = serverURL
}