[VOL-2471] Update library to use package logger
This commit consists of the following:
1) Add a GetLogLevel() API to make it easier to use specific
logger. There is also the V() API that kind of do something
similar.
2) Add a common.go file to some heavily used packages in order
to dynamically set their log level and also to a set a specific
logger per package.
3) Use a per package logger for some of the heavily used packages
for improved performance.
Change-Id: If22a2c82d87d808f305677a2e793f8064f33291e
diff --git a/pkg/db/backend.go b/pkg/db/backend.go
index b2547c2..b807253 100644
--- a/pkg/db/backend.go
+++ b/pkg/db/backend.go
@@ -65,7 +65,7 @@
address := host + ":" + strconv.Itoa(port)
if b.Client, err = b.newClient(address, timeout); err != nil {
- log.Errorw("failed-to-create-kv-client",
+ logger.Errorw("failed-to-create-kv-client",
log.Fields{
"type": storeType, "host": host, "port": port,
"timeout": timeout, "prefix": pathPrefix,
@@ -99,11 +99,11 @@
if b.liveness != nil {
if b.alive != alive {
- log.Debug("update-liveness-channel-reason-change")
+ logger.Debug("update-liveness-channel-reason-change")
b.liveness <- alive
b.lastLivenessTime = time.Now()
} else if time.Now().Sub(b.lastLivenessTime) > b.LivenessChannelInterval {
- log.Debug("update-liveness-channel-reason-interval")
+ logger.Debug("update-liveness-channel-reason-interval")
b.liveness <- alive
b.lastLivenessTime = time.Now()
}
@@ -111,7 +111,7 @@
// Emit log message only for alive state change
if b.alive != alive {
- log.Debugw("change-kvstore-alive-status", log.Fields{"alive": alive})
+ logger.Debugw("change-kvstore-alive-status", log.Fields{"alive": alive})
b.alive = alive
}
}
@@ -120,7 +120,7 @@
// post on Liveness channel
func (b *Backend) PerformLivenessCheck(timeout int) bool {
alive := b.Client.IsConnectionUp(timeout)
- log.Debugw("kvstore-liveness-check-result", log.Fields{"alive": alive})
+ logger.Debugw("kvstore-liveness-check-result", log.Fields{"alive": alive})
b.updateLiveness(alive)
return alive
@@ -132,10 +132,10 @@
// by the service (i.e. rw_core / ro_core) to update readiness status
// and/or take other actions.
func (b *Backend) EnableLivenessChannel() chan bool {
- log.Debug("enable-kvstore-liveness-channel")
+ logger.Debug("enable-kvstore-liveness-channel")
if b.liveness == nil {
- log.Debug("create-kvstore-liveness-channel")
+ logger.Debug("create-kvstore-liveness-channel")
// Channel size of 10 to avoid any possibility of blocking in Load conditions
b.liveness = make(chan bool, 10)
@@ -191,7 +191,7 @@
defer b.Unlock()
formattedPath := b.makePath(key)
- log.Debugw("listing-key", log.Fields{"key": key, "path": formattedPath})
+ logger.Debugw("listing-key", log.Fields{"key": key, "path": formattedPath})
pair, err := b.Client.List(formattedPath, b.Timeout)
@@ -206,7 +206,7 @@
defer b.Unlock()
formattedPath := b.makePath(key)
- log.Debugw("getting-key", log.Fields{"key": key, "path": formattedPath})
+ logger.Debugw("getting-key", log.Fields{"key": key, "path": formattedPath})
pair, err := b.Client.Get(formattedPath, b.Timeout)
@@ -221,7 +221,7 @@
defer b.Unlock()
formattedPath := b.makePath(key)
- log.Debugw("putting-key", log.Fields{"key": key, "value": string(value.([]byte)), "path": formattedPath})
+ logger.Debugw("putting-key", log.Fields{"key": key, "value": string(value.([]byte)), "path": formattedPath})
err := b.Client.Put(formattedPath, value, b.Timeout)
@@ -236,7 +236,7 @@
defer b.Unlock()
formattedPath := b.makePath(key)
- log.Debugw("deleting-key", log.Fields{"key": key, "path": formattedPath})
+ logger.Debugw("deleting-key", log.Fields{"key": key, "path": formattedPath})
err := b.Client.Delete(formattedPath, b.Timeout)
@@ -251,7 +251,7 @@
defer b.Unlock()
formattedPath := b.makePath(key)
- log.Debugw("creating-key-watch", log.Fields{"key": key, "path": formattedPath})
+ logger.Debugw("creating-key-watch", log.Fields{"key": key, "path": formattedPath})
return b.Client.Watch(formattedPath)
}
@@ -262,7 +262,7 @@
defer b.Unlock()
formattedPath := b.makePath(key)
- log.Debugw("deleting-key-watch", log.Fields{"key": key, "path": formattedPath})
+ logger.Debugw("deleting-key-watch", log.Fields{"key": key, "path": formattedPath})
b.Client.CloseWatch(formattedPath, ch)
}