[VOL-2694] Use package specific logger instance in all log statements
Change-Id: Icf1cb5ade42e42179aed7731b767af2f52481e3d
diff --git a/rw_core/mocks/adapter_olt.go b/rw_core/mocks/adapter_olt.go
index 46f0e28..4d58f00 100644
--- a/rw_core/mocks/adapter_olt.go
+++ b/rw_core/mocks/adapter_olt.go
@@ -64,7 +64,7 @@
d.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
oltA.storeDevice(d)
if res := oltA.coreProxy.DeviceUpdate(context.TODO(), d); res != nil {
- log.Fatalf("deviceUpdate-failed-%s", res)
+ logger.Fatalf("deviceUpdate-failed-%s", res)
}
nniPort := &voltha.Port{
PortNo: 2,
@@ -74,7 +74,7 @@
}
var err error
if err = oltA.coreProxy.PortCreated(context.TODO(), d.Id, nniPort); err != nil {
- log.Fatalf("PortCreated-failed-%s", err)
+ logger.Fatalf("PortCreated-failed-%s", err)
}
ponPort := &voltha.Port{
@@ -84,23 +84,23 @@
OperStatus: voltha.OperStatus_ACTIVE,
}
if err = oltA.coreProxy.PortCreated(context.TODO(), d.Id, ponPort); err != nil {
- log.Fatalf("PortCreated-failed-%s", err)
+ logger.Fatalf("PortCreated-failed-%s", err)
}
d.ConnectStatus = voltha.ConnectStatus_REACHABLE
d.OperStatus = voltha.OperStatus_ACTIVE
if err = oltA.coreProxy.DeviceStateUpdate(context.TODO(), d.Id, d.ConnectStatus, d.OperStatus); err != nil {
- log.Fatalf("Device-state-update-failed-%s", err)
+ logger.Fatalf("Device-state-update-failed-%s", err)
}
//Get the latest device data from the Core
if d, err = oltA.coreProxy.GetDevice(context.TODO(), d.Id, d.Id); err != nil {
- log.Fatalf("getting-device-failed-%s", err)
+ logger.Fatalf("getting-device-failed-%s", err)
}
if err = oltA.updateDevice(d); err != nil {
- log.Fatalf("saving-device-failed-%s", err)
+ logger.Fatalf("saving-device-failed-%s", err)
}
// Register Child devices
@@ -116,7 +116,7 @@
"onu_adapter_mock",
com.GetRandomSerialNumber(),
int64(seqNo)); err != nil {
- log.Fatalf("failure-sending-child-device-%s", err)
+ logger.Fatalf("failure-sending-child-device-%s", err)
}
}(i)
}
@@ -127,7 +127,7 @@
// Get_ofp_device_info returns ofp device info
func (oltA *OLTAdapter) Get_ofp_device_info(device *voltha.Device) (*ic.SwitchCapability, error) { // nolint
if d := oltA.getDevice(device.Id); d == nil {
- log.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf("device-not-found-%s", device.Id)
}
return &ic.SwitchCapability{
Desc: &of.OfpDesc{
@@ -149,7 +149,7 @@
// Get_ofp_port_info returns ofp port info
func (oltA *OLTAdapter) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint
if d := oltA.getDevice(device.Id); d == nil {
- log.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf("device-not-found-%s", device.Id)
}
capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
return &ic.PortCapability{
@@ -184,13 +184,13 @@
func (oltA *OLTAdapter) Disable_device(device *voltha.Device) error { // nolint
go func() {
if d := oltA.getDevice(device.Id); d == nil {
- log.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf("device-not-found-%s", device.Id)
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to disable
if err := oltA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
- log.Warnw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
}
//Update the device operational state
@@ -199,18 +199,18 @@
if err := oltA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
// Device may already have been deleted in the core
- log.Warnw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
return
}
if err := oltA.updateDevice(cloned); err != nil {
- log.Fatalf("saving-device-failed-%s", err)
+ logger.Fatalf("saving-device-failed-%s", err)
}
// Tell the Core that all child devices have been disabled (by default it's an action already taken by the Core
if err := oltA.coreProxy.ChildDevicesLost(context.TODO(), cloned.Id); err != nil {
// Device may already have been deleted in the core
- log.Warnw("lost-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw("lost-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err})
}
}()
return nil
@@ -220,25 +220,25 @@
func (oltA *OLTAdapter) Reenable_device(device *voltha.Device) error { // nolint
go func() {
if d := oltA.getDevice(device.Id); d == nil {
- log.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf("device-not-found-%s", device.Id)
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to enable
if err := oltA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
- log.Fatalf("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
}
//Update the device state
cloned.OperStatus = voltha.OperStatus_ACTIVE
if err := oltA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- log.Fatalf("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
}
// Tell the Core that all child devices have been enabled
if err := oltA.coreProxy.ChildDevicesDetected(context.TODO(), cloned.Id); err != nil {
- log.Fatalf("detection-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf("detection-notif-of-child-devices-failed", log.Fields{"deviceId": device.Id, "error": err})
}
}()
return nil
@@ -250,7 +250,7 @@
if Port.Type == voltha.Port_PON_OLT {
if err := oltA.coreProxy.PortStateUpdate(context.TODO(), deviceId, voltha.Port_PON_OLT, Port.PortNo, voltha.OperStatus_ACTIVE); err != nil {
- log.Fatalf("updating-ports-failed", log.Fields{"device-id": deviceId, "error": err})
+ logger.Fatalf("updating-ports-failed", log.Fields{"device-id": deviceId, "error": err})
}
}
@@ -265,7 +265,7 @@
if Port.Type == voltha.Port_PON_OLT {
if err := oltA.coreProxy.PortStateUpdate(context.TODO(), deviceId, voltha.Port_PON_OLT, Port.PortNo, voltha.OperStatus_DISCOVERED); err != nil {
// Corresponding device may have been deleted
- log.Warnw("updating-ports-failed", log.Fields{"device-id": deviceId, "error": err})
+ logger.Warnw("updating-ports-failed", log.Fields{"device-id": deviceId, "error": err})
}
}
}()
@@ -297,14 +297,14 @@
// Reboot_device -
func (oltA *OLTAdapter) Reboot_device(device *voltha.Device) error { // nolint
- log.Infow("reboot-device", log.Fields{"deviceId": device.Id})
+ logger.Infow("reboot-device", log.Fields{"deviceId": device.Id})
go func() {
if err := oltA.coreProxy.DeviceStateUpdate(context.TODO(), device.Id, voltha.ConnectStatus_UNREACHABLE, voltha.OperStatus_UNKNOWN); err != nil {
- log.Fatalf("device-state-update-failed", log.Fields{"device-id": device.Id})
+ logger.Fatalf("device-state-update-failed", log.Fields{"device-id": device.Id})
}
if err := oltA.coreProxy.PortsStateUpdate(context.TODO(), device.Id, voltha.OperStatus_UNKNOWN); err != nil {
- log.Fatalf("port-update-failed", log.Fields{"device-id": device.Id})
+ logger.Fatalf("port-update-failed", log.Fields{"device-id": device.Id})
}
}()
return nil
diff --git a/rw_core/mocks/adapter_onu.go b/rw_core/mocks/adapter_onu.go
index c31cb93..92dff06 100644
--- a/rw_core/mocks/adapter_onu.go
+++ b/rw_core/mocks/adapter_onu.go
@@ -59,14 +59,14 @@
d.MacAddress = strings.ToUpper(com.GetRandomMacAddress())
onuA.storeDevice(d)
if res := onuA.coreProxy.DeviceUpdate(context.TODO(), d); res != nil {
- log.Fatalf("deviceUpdate-failed-%s", res)
+ logger.Fatalf("deviceUpdate-failed-%s", res)
}
d.ConnectStatus = voltha.ConnectStatus_REACHABLE
d.OperStatus = voltha.OperStatus_DISCOVERED
if err := onuA.coreProxy.DeviceStateUpdate(context.TODO(), d.Id, d.ConnectStatus, d.OperStatus); err != nil {
- log.Fatalf("device-state-update-failed-%s", err)
+ logger.Fatalf("device-state-update-failed-%s", err)
}
uniPortNo := uint32(2)
@@ -84,7 +84,7 @@
}
var err error
if err = onuA.coreProxy.PortCreated(context.TODO(), d.Id, uniPort); err != nil {
- log.Fatalf("PortCreated-failed-%s", err)
+ logger.Fatalf("PortCreated-failed-%s", err)
}
ponPortNo := uint32(1)
@@ -101,22 +101,22 @@
PortNo: device.ParentPortNo}}, // Peer port is parent's port number
}
if err = onuA.coreProxy.PortCreated(context.TODO(), d.Id, ponPort); err != nil {
- log.Fatalf("PortCreated-failed-%s", err)
+ logger.Fatalf("PortCreated-failed-%s", err)
}
d.ConnectStatus = voltha.ConnectStatus_REACHABLE
d.OperStatus = voltha.OperStatus_ACTIVE
if err = onuA.coreProxy.DeviceStateUpdate(context.TODO(), d.Id, d.ConnectStatus, d.OperStatus); err != nil {
- log.Fatalf("device-state-update-failed-%s", err)
+ logger.Fatalf("device-state-update-failed-%s", err)
}
//Get the latest device data from the Core
if d, err = onuA.coreProxy.GetDevice(context.TODO(), d.Id, d.Id); err != nil {
- log.Fatalf("getting-device-failed-%s", err)
+ logger.Fatalf("getting-device-failed-%s", err)
}
if err = onuA.updateDevice(d); err != nil {
- log.Fatalf("saving-device-failed-%s", err)
+ logger.Fatalf("saving-device-failed-%s", err)
}
}()
return nil
@@ -125,7 +125,7 @@
// Get_ofp_port_info returns ofp device info
func (onuA *ONUAdapter) Get_ofp_port_info(device *voltha.Device, portNo int64) (*ic.PortCapability, error) { // nolint
if d := onuA.getDevice(device.Id); d == nil {
- log.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf("device-not-found-%s", device.Id)
}
capability := uint32(of.OfpPortFeatures_OFPPF_1GB_FD | of.OfpPortFeatures_OFPPF_FIBER)
return &ic.PortCapability{
@@ -150,13 +150,13 @@
func (onuA *ONUAdapter) Disable_device(device *voltha.Device) error { // nolint
go func() {
if d := onuA.getDevice(device.Id); d == nil {
- log.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf("device-not-found-%s", device.Id)
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to disable
if err := onuA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_UNKNOWN); err != nil {
// Device may also have been deleted in the Core
- log.Warnw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
return
}
//Update the device state
@@ -164,11 +164,11 @@
cloned.OperStatus = voltha.OperStatus_UNKNOWN
if err := onuA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- log.Warnw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Warnw("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
return
}
if err := onuA.updateDevice(cloned); err != nil {
- log.Fatalf("saving-device-failed-%s", err)
+ logger.Fatalf("saving-device-failed-%s", err)
}
}()
return nil
@@ -178,13 +178,13 @@
func (onuA *ONUAdapter) Reenable_device(device *voltha.Device) error { // nolint
go func() {
if d := onuA.getDevice(device.Id); d == nil {
- log.Fatalf("device-not-found-%s", device.Id)
+ logger.Fatalf("device-not-found-%s", device.Id)
}
cloned := proto.Clone(device).(*voltha.Device)
// Update the all ports state on that device to enable
if err := onuA.coreProxy.PortsStateUpdate(context.TODO(), cloned.Id, voltha.OperStatus_ACTIVE); err != nil {
- log.Fatalf("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf("updating-ports-failed", log.Fields{"deviceId": device.Id, "error": err})
}
//Update the device state
@@ -192,10 +192,10 @@
cloned.OperStatus = voltha.OperStatus_ACTIVE
if err := onuA.coreProxy.DeviceStateUpdate(context.TODO(), cloned.Id, cloned.ConnectStatus, cloned.OperStatus); err != nil {
- log.Fatalf("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
+ logger.Fatalf("device-state-update-failed", log.Fields{"deviceId": device.Id, "error": err})
}
if err := onuA.updateDevice(cloned); err != nil {
- log.Fatalf("saving-device-failed-%s", err)
+ logger.Fatalf("saving-device-failed-%s", err)
}
}()
return nil
diff --git a/rw_core/mocks/common_test.go b/rw_core/mocks/common.go
similarity index 73%
rename from rw_core/mocks/common_test.go
rename to rw_core/mocks/common.go
index eb1534f..3b2df29 100644
--- a/rw_core/mocks/common_test.go
+++ b/rw_core/mocks/common.go
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-present Open Networking Foundation
+ * 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.
@@ -13,21 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+// Package mocks Common Logger initialization
package mocks
import (
"github.com/opencord/voltha-lib-go/v3/pkg/log"
)
-const (
- logLevel = log.FatalLevel
-)
+var logger log.Logger
-// Unit test initialization. This init() function handles all unit tests in
-// the current directory.
func init() {
// Setup this package so that it's log level can be modified at run time
- _, err := log.AddPackage(log.JSON, logLevel, log.Fields{"instanceId": "mocks"})
+ var err error
+ logger, err = log.AddPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "mocks"})
if err != nil {
panic(err)
}