[VOL-3424] Switch completely to Context based Logger instance
Change-Id: I394ec682d4a8237740612de95826668e109f84b4
diff --git a/cmd/openolt-adapter/main.go b/cmd/openolt-adapter/main.go
index ee41299..14738df 100644
--- a/cmd/openolt-adapter/main.go
+++ b/cmd/openolt-adapter/main.go
@@ -474,12 +474,12 @@
// Setup default logger - applies for packages that do not have specific logger set
if _, err := log.SetDefaultLogger(log.JSON, logLevel, log.Fields{"instanceId": cf.InstanceID}); err != nil {
- log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
+ logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging")
}
// Update all loggers (provisionned via init) with a common field
if err := log.UpdateAllLoggers(log.Fields{"instanceId": cf.InstanceID}); err != nil {
- log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
+ logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging")
}
log.SetAllLogLevel(logLevel)
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 7c7dc06..55cf231 100644
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -270,7 +270,7 @@
}
if port, err := dh.coreProxy.GetDevicePort(log.WithSpanFromContext(context.TODO(), ctx), dh.device.Id, portNum); err == nil && port.Type == portType {
- log.Debug(ctx, "port-already-exists-updating-oper-status-of-port")
+ logger.Debug(ctx, "port-already-exists-updating-oper-status-of-port")
if err := dh.coreProxy.PortStateUpdate(log.WithSpanFromContext(context.TODO(), ctx), dh.device.Id, portType, portNum, operStatus); err != nil {
return olterrors.NewErrAdapter("failed-to-update-port-state", log.Fields{
"device-id": dh.device.Id,
@@ -2103,11 +2103,11 @@
}
dh.lockDevice.RUnlock()
- log.Debugw("wait-for-flow-remove-complete-before-processing-child-device-lost",
+ logger.Debugw(ctx, "wait-for-flow-remove-complete-before-processing-child-device-lost",
log.Fields{"int-id": intfID, "onu-id": onuID, "uni-id": uniID})
// Wait for all flow removes to finish first
<-flowRemoveData.allFlowsRemoved
- log.Debugw("flow-removes-complete-for-subscriber",
+ logger.Debugw(ctx, "flow-removes-complete-for-subscriber",
log.Fields{"int-id": intfID, "onu-id": onuID, "uni-id": uniID})
}
@@ -2321,7 +2321,7 @@
resp := new(voltha.ReturnValues)
valueparam := new(oop.ValueParam)
ctx = log.WithSpanFromContext(context.Background(), ctx)
- log.Infow("getExtValue", log.Fields{"onu-id": device.Id, "pon-intf": device.ParentPortNo})
+ logger.Infow(ctx, "getExtValue", log.Fields{"onu-id": device.Id, "pon-intf": device.ParentPortNo})
if sn, err = dh.deStringifySerialNumber(device.SerialNumber); err != nil {
return nil, err
}
@@ -2338,11 +2338,11 @@
/*
resp, err = dh.Client.GetValue(ctx, valueparam)
if err != nil {
- log.Errorw("error-while-getValue", log.Fields{"DeviceID": dh.device, "onu-id": onuid, "error": err})
+ logger.Errorw("error-while-getValue", log.Fields{"DeviceID": dh.device, "onu-id": onuid, "error": err})
return nil, err
}
*/
- log.Infow("get-ext-value", log.Fields{"resp": resp, "device-id": dh.device, "onu-id": device.Id, "pon-intf": device.ParentPortNo})
+ logger.Infow(ctx, "get-ext-value", log.Fields{"resp": resp, "device-id": dh.device, "onu-id": device.Id, "pon-intf": device.ParentPortNo})
return resp, nil
}
diff --git a/internal/pkg/core/openolt.go b/internal/pkg/core/openolt.go
index 453b9da..f694c36 100644
--- a/internal/pkg/core/openolt.go
+++ b/internal/pkg/core/openolt.go
@@ -358,10 +358,10 @@
func (oo *OpenOLT) Get_ext_value(ctx context.Context, deviceID string, device *voltha.Device, valueparam voltha.ValueType_Type) (*voltha.ReturnValues, error) {
var err error
resp := new(voltha.ReturnValues)
- log.Infow("Get_ext_value", log.Fields{"device-id": deviceID, "onu-id": device.Id})
+ logger.Infow(ctx, "Get_ext_value", log.Fields{"device-id": deviceID, "onu-id": device.Id})
if handler := oo.getDeviceHandler(deviceID); handler != nil {
if resp, err = handler.getExtValue(ctx, device, valueparam); err != nil {
- log.Errorw("error-occurred-during-get-ext-value", log.Fields{"device-id": deviceID, "onu-id": device.Id,
+ logger.Errorw(ctx, "error-occurred-during-get-ext-value", log.Fields{"device-id": deviceID, "onu-id": device.Id,
"error": err})
return nil, err
}
diff --git a/internal/pkg/core/openolt_eventmgr.go b/internal/pkg/core/openolt_eventmgr.go
index 8a58303..584cfe0 100644
--- a/internal/pkg/core/openolt_eventmgr.go
+++ b/internal/pkg/core/openolt_eventmgr.go
@@ -802,6 +802,6 @@
if err := em.eventProxy.SendDeviceEvent(ctx, de, voltha.EventCategory_EQUIPMENT, voltha.EventSubCategory_ONU, raisedTs); err != nil {
return err
}
- log.Debugw("onu-differential-reach-exceeded–event-sent-to-kafka", log.Fields{"onu-id": onuDRE.OnuId, "intf-id": onuDRE.IntfId})
+ logger.Debugw(ctx, "onu-differential-reach-exceeded–event-sent-to-kafka", log.Fields{"onu-id": onuDRE.OnuId, "intf-id": onuDRE.IntfId})
return nil
}
diff --git a/internal/pkg/core/openolt_flowmgr.go b/internal/pkg/core/openolt_flowmgr.go
index 709735a..03f5e8b 100644
--- a/internal/pkg/core/openolt_flowmgr.go
+++ b/internal/pkg/core/openolt_flowmgr.go
@@ -979,7 +979,7 @@
}
if _, ok := classifier[VlanVid]; ok {
vlanVid = classifier[VlanVid].(uint32)
- log.Debugw("found-vlan-in-the-flow",
+ logger.Debugw(ctx, "found-vlan-in-the-flow",
log.Fields{
"vlan-vid": vlanVid,
"intf-id": intfID,
@@ -1485,7 +1485,7 @@
// return err
// We should continue to delete tech-profile instances for other TP IDs
}
- log.Debugw("tech-profile-deleted", log.Fields{"device-id": f.deviceHandler.device.Id, "tp-id": tpID})
+ logger.Debugw(ctx, "tech-profile-deleted", log.Fields{"device-id": f.deviceHandler.device.Id, "tp-id": tpID})
}
return nil
}
@@ -3777,7 +3777,7 @@
} else if fieldtype == ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP {
pcp := ofbField.GetVlanPcp()
actionInfo[VlanPcp] = pcp
- log.Debugw("action-set-vlan-pcp", log.Fields{"actionInfo[VLAN_PCP]": actionInfo[VlanPcp].(uint32)})
+ logger.Debugw(ctx, "action-set-vlan-pcp", log.Fields{"actionInfo[VLAN_PCP]": actionInfo[VlanPcp].(uint32)})
} else {
logger.Errorw(ctx, "unsupported-action-set-field-type", log.Fields{"type": fieldtype})
}
@@ -3938,7 +3938,7 @@
//getCTagFromPacket retrieves and returns c-tag and priority value from a packet.
func getCTagFromPacket(ctx context.Context, packet []byte) (uint16, uint8, error) {
if packet == nil || len(packet) < 18 {
- log.Error("unable-get-c-tag-from-the-packet--invalid-packet-length ")
+ logger.Error(ctx, "unable-get-c-tag-from-the-packet--invalid-packet-length ")
return 0, 0, errors.New("invalid packet length")
}
outerEthType := (uint16(packet[12]) << 8) | uint16(packet[13])
diff --git a/internal/pkg/olterrors/common.go b/internal/pkg/olterrors/common.go
new file mode 100644
index 0000000..7709046
--- /dev/null
+++ b/internal/pkg/olterrors/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 olterrors Common Logger initialization
+package olterrors
+
+import (
+ "github.com/opencord/voltha-lib-go/v3/pkg/log"
+)
+
+var logger log.CLogger
+
+func init() {
+ // Setup this package so that it's log level can be modified at run time
+ var err error
+ logger, err = log.RegisterPackage(log.JSON, log.ErrorLevel, log.Fields{})
+ if err != nil {
+ panic(err)
+ }
+}
diff --git a/internal/pkg/olterrors/olterrors.go b/internal/pkg/olterrors/olterrors.go
index 7aa66ca..59eaed9 100644
--- a/internal/pkg/olterrors/olterrors.go
+++ b/internal/pkg/olterrors/olterrors.go
@@ -18,6 +18,7 @@
package olterrors
import (
+ "context"
"encoding/json"
"fmt"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
@@ -111,22 +112,22 @@
// LogAt logs the error at the specified level and then returns the error
func (e *ErrAdapter) LogAt(level log.LogLevel) error {
- logger := log.Debugw
+ loggerFunc := logger.Debugw
switch level {
case log.InfoLevel:
- logger = log.Infow
+ loggerFunc = logger.Infow
case log.WarnLevel:
- logger = log.Warnw
+ loggerFunc = logger.Warnw
case log.ErrorLevel:
- logger = log.Errorw
+ loggerFunc = logger.Errorw
case log.FatalLevel:
- logger = log.Fatalw
+ loggerFunc = logger.Fatalw
}
local := e.fields
if e.wrapped != nil {
local = merge(e.fields, log.Fields{"wrapped": e.wrapped})
}
- logger(e.name, local)
+ loggerFunc(context.Background(), e.name, local)
return e
}
diff --git a/internal/pkg/resourcemanager/resourcemanager.go b/internal/pkg/resourcemanager/resourcemanager.go
index 0504eaf..a2c9286 100755
--- a/internal/pkg/resourcemanager/resourcemanager.go
+++ b/internal/pkg/resourcemanager/resourcemanager.go
@@ -519,7 +519,7 @@
FlowInfo := RsrcMgr.GetFlowIDInfo(ctx, ponIntfID, int32(ONUID), int32(uniID), uint32(flowID))
er := getFlowIDFromFlowInfo(ctx, FlowInfo, flowID, gemportID, flowStoreCookie, flowCategory, vlanVid, vlanPcp...)
if er == nil {
- log.Debugw("Found flowid for the vlan, pcp, and gem",
+ logger.Debugw(ctx, "Found flowid for the vlan, pcp, and gem",
log.Fields{"flowID": flowID, "vlanVid": vlanVid, "vlanPcp": vlanPcp, "gemPortID": gemportID})
return flowID, er
}