[VOL-2027] Included instanceId in log message
Change-Id: I83e54640169d9a010ea0a644e8e3ef8ed0663827
diff --git a/cmd/arouter/arouter.go b/cmd/arouter/arouter.go
index abea7b0..d3838ac 100644
--- a/cmd/arouter/arouter.go
+++ b/cmd/arouter/arouter.go
@@ -36,7 +36,7 @@
}
// Setup logging
- if _, err := log.SetDefaultLogger(log.JSON, *conf.LogLevel, nil); err != nil {
+ if _, err := log.SetDefaultLogger(log.JSON, *conf.LogLevel, log.Fields{"instanceId": conf.InstanceID}); err != nil {
log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
}
diff --git a/cmd/arouterd/arouterd.go b/cmd/arouterd/arouterd.go
index 2c6b31e..1c9cd80 100644
--- a/cmd/arouterd/arouterd.go
+++ b/cmd/arouterd/arouterd.go
@@ -82,6 +82,8 @@
kafkaHost = getStrEnv("KAFKA_HOST", "kafka")
kafkaPort = getIntEnv("KAFKA_PORT", 0, math.MaxUint16, 9092)
kafkaInstanceID = getStrEnv("KAFKA_INSTANCE_ID", "arouterd")
+
+ instanceID = getStrEnv("HOSTNAME", "arouterd001")
)
func getIntEnv(key string, min, max, defaultValue int) int {
@@ -411,7 +413,7 @@
}
// Set up logging
- if _, err := log.SetDefaultLogger(log.JSON, 0, nil); err != nil {
+ if _, err := log.SetDefaultLogger(log.JSON, 0, log.Fields{"instanceId": instanceID}); err != nil {
log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
}
diff --git a/internal/pkg/afrouter/affinity-router_test.go b/internal/pkg/afrouter/affinity-router_test.go
index 6dfb969..e78b948 100644
--- a/internal/pkg/afrouter/affinity-router_test.go
+++ b/internal/pkg/afrouter/affinity-router_test.go
@@ -34,7 +34,7 @@
// Unit test initialization
func init() {
// Logger must be configured or bad things happen
- log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
+ log.SetDefaultLogger(log.JSON, log.DebugLevel, log.Fields{"instanceId": 1})
log.AddPackage(log.JSON, log.WarnLevel, nil)
}
diff --git a/internal/pkg/afrouter/config.go b/internal/pkg/afrouter/config.go
index 6008199..09e1816 100644
--- a/internal/pkg/afrouter/config.go
+++ b/internal/pkg/afrouter/config.go
@@ -29,6 +29,10 @@
"path"
)
+const (
+ default_InstanceID = "arouter001"
+)
+
func ParseCmd() (*Configuration, error) {
config := &Configuration{}
cmdParse := flag.NewFlagSet(path.Base(os.Args[0]), flag.ContinueOnError)
@@ -44,11 +48,19 @@
}
//if(!cmdParse.Parsed()) {
//}
+
+ if val, have := os.LookupEnv("HOSTNAME"); have {
+ config.InstanceID = val
+ } else {
+ config.InstanceID = default_InstanceID
+ }
+
return config, nil
}
// Configuration file loading and parsing
type Configuration struct {
+ InstanceID string
ConfigFile *string
LogLevel *int
GrpcLog *bool
diff --git a/internal/pkg/afrouter/method-router_test.go b/internal/pkg/afrouter/method-router_test.go
index 2214595..47204dd 100644
--- a/internal/pkg/afrouter/method-router_test.go
+++ b/internal/pkg/afrouter/method-router_test.go
@@ -34,7 +34,7 @@
// Unit test initialization
func init() {
// Logger must be configured or bad things happen
- log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
+ log.SetDefaultLogger(log.JSON, log.DebugLevel, log.Fields{"instanceId": 1})
log.AddPackage(log.JSON, log.WarnLevel, nil)
}
diff --git a/internal/pkg/afrouter/round-robin-router_test.go b/internal/pkg/afrouter/round-robin-router_test.go
index 5d8331e..972832e 100644
--- a/internal/pkg/afrouter/round-robin-router_test.go
+++ b/internal/pkg/afrouter/round-robin-router_test.go
@@ -31,7 +31,7 @@
)
func init() {
- log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
+ log.SetDefaultLogger(log.JSON, log.DebugLevel, log.Fields{"instanceId": 1})
log.AddPackage(log.JSON, log.WarnLevel, nil)
}
diff --git a/internal/pkg/afrouter/router_test.go b/internal/pkg/afrouter/router_test.go
index 2da77e3..940f6cc 100644
--- a/internal/pkg/afrouter/router_test.go
+++ b/internal/pkg/afrouter/router_test.go
@@ -23,7 +23,7 @@
)
func init() {
- log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
+ log.SetDefaultLogger(log.JSON, log.DebugLevel, log.Fields{"instanceId": 1})
log.AddPackage(log.JSON, log.WarnLevel, nil)
}
diff --git a/internal/pkg/afrouter/server_test.go b/internal/pkg/afrouter/server_test.go
index f67f8cb..162937c 100644
--- a/internal/pkg/afrouter/server_test.go
+++ b/internal/pkg/afrouter/server_test.go
@@ -24,7 +24,7 @@
)
func init() {
- log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
+ log.SetDefaultLogger(log.JSON, log.DebugLevel, log.Fields{"instanceId": 1})
log.AddPackage(log.JSON, log.WarnLevel, nil)
}
diff --git a/internal/pkg/afrouter/signals_test.go b/internal/pkg/afrouter/signals_test.go
index 3d72ac4..4033b70 100644
--- a/internal/pkg/afrouter/signals_test.go
+++ b/internal/pkg/afrouter/signals_test.go
@@ -27,7 +27,7 @@
)
func init() {
- log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
+ log.SetDefaultLogger(log.JSON, log.DebugLevel, log.Fields{"instanceId": 1})
log.AddPackage(log.JSON, log.WarnLevel, nil)
}
diff --git a/internal/pkg/afrouter/source-router_test.go b/internal/pkg/afrouter/source-router_test.go
index 2a9f9d2..b33916c 100644
--- a/internal/pkg/afrouter/source-router_test.go
+++ b/internal/pkg/afrouter/source-router_test.go
@@ -29,7 +29,7 @@
)
func init() {
- log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
+ log.SetDefaultLogger(log.JSON, log.DebugLevel, log.Fields{"instanceId": 1})
log.AddPackage(log.JSON, log.WarnLevel, nil)
}