[VOL-2694] Use package specific logger instance in all log statements
Change-Id: Icf1cb5ade42e42179aed7731b767af2f52481e3d
diff --git a/rw_core/route/common.go b/rw_core/route/common.go
new file mode 100644
index 0000000..e47f8c9
--- /dev/null
+++ b/rw_core/route/common.go
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Package route Common Logger initialization
+package route
+
+import (
+ "github.com/opencord/voltha-lib-go/v3/pkg/log"
+)
+
+var logger log.Logger
+
+func init() {
+ // Setup this package so that it's log level can be modified at run time
+ var err error
+ logger, err = log.AddPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "route"})
+ if err != nil {
+ panic(err)
+ }
+}
diff --git a/rw_core/route/device_route.go b/rw_core/route/device_route.go
index c22ff2a..a36c841 100644
--- a/rw_core/route/device_route.go
+++ b/rw_core/route/device_route.go
@@ -26,13 +26,6 @@
"sync"
)
-func init() {
- _, err := log.AddPackage(log.JSON, log.WarnLevel, nil)
- if err != nil {
- log.Fatalw("unable-to-register-package-to-the-log-map", log.Fields{"error": err})
- }
-}
-
// Hop represent a route hop
type Hop struct {
DeviceID string
@@ -75,7 +68,7 @@
dr.RootPorts = make(map[uint32]uint32)
dr.Routes = make(map[PathID][]Hop)
dr.devicesPonPorts = make(map[string][]*voltha.Port)
- log.Debug("new device routes created ...")
+ logger.Debug("new device routes created ...")
return &dr
}
@@ -92,7 +85,7 @@
dr.routeBuildLock.Lock()
defer dr.routeBuildLock.Unlock()
- log.Debugw("computing-all-routes", log.Fields{"len-logical-ports": len(lps)})
+ logger.Debugw("computing-all-routes", log.Fields{"len-logical-ports": len(lps)})
var err error
defer func() {
// On error, clear the routes - any flow request or a port add/delete will trigger the rebuild
@@ -143,7 +136,7 @@
}
for _, rootDevicePort := range rootDevice.Ports {
if rootDevicePort.Type == voltha.Port_PON_OLT {
- log.Debugw("peers", log.Fields{"root-device-id": rootDevice.Id, "port-no": rootDevicePort.PortNo, "len-peers": len(rootDevicePort.Peers)})
+ logger.Debugw("peers", log.Fields{"root-device-id": rootDevice.Id, "port-no": rootDevicePort.PortNo, "len-peers": len(rootDevicePort.Peers)})
for _, rootDevicePeer := range rootDevicePort.Peers {
childDevice, err = dr.getDevice(ctx, rootDevicePeer.DeviceId)
if err != nil {
@@ -206,7 +199,7 @@
// AddPort augments the current set of routes with new routes corresponding to the logical port "lp". If the routes have
// not been built yet then use logical port "lps" to compute all current routes (lps includes lp)
func (dr *DeviceRoutes) AddPort(ctx context.Context, lp *voltha.LogicalPort, lps []*voltha.LogicalPort) error {
- log.Debugw("add-port-to-routes", log.Fields{"port": lp, "len-logical-ports": len(lps)})
+ logger.Debugw("add-port-to-routes", log.Fields{"port": lp, "len-logical-ports": len(lps)})
dr.routeBuildLock.Lock()
if len(dr.Routes) == 0 {
@@ -280,8 +273,8 @@
// Print prints routes
func (dr *DeviceRoutes) Print() error {
- log.Debugw("Print", log.Fields{"logical-device-id": dr.logicalDeviceID, "logical-ports": dr.logicalPorts})
- if log.V(log.DebugLevel) {
+ logger.Debugw("Print", log.Fields{"logical-device-id": dr.logicalDeviceID, "logical-ports": dr.logicalPorts})
+ if logger.V(log.DebugLevel) {
output := ""
routeNumber := 1
for k, v := range dr.Routes {
@@ -295,9 +288,9 @@
routeNumber++
}
if len(dr.Routes) == 0 {
- log.Debugw("no-routes-found", log.Fields{"logical-device-id": dr.logicalDeviceID})
+ logger.Debugw("no-routes-found", log.Fields{"logical-device-id": dr.logicalDeviceID})
} else {
- log.Debugw("graph_routes", log.Fields{"lDeviceId": dr.logicalDeviceID, "Routes": output})
+ logger.Debugw("graph_routes", log.Fields{"lDeviceId": dr.logicalDeviceID, "Routes": output})
}
}
return nil
@@ -342,7 +335,7 @@
func (dr *DeviceRoutes) getDevice(ctx context.Context, deviceID string) (*voltha.Device, error) {
device, err := dr.getDeviceFromModel(ctx, deviceID)
if err != nil {
- log.Errorw("device-not-found", log.Fields{"deviceId": deviceID, "error": err})
+ logger.Errorw("device-not-found", log.Fields{"deviceId": deviceID, "error": err})
return nil, err
}
dr.devicesPonPortsLock.Lock()