[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/flows/common.go b/pkg/flows/common.go
new file mode 100644
index 0000000..de85acf
--- /dev/null
+++ b/pkg/flows/common.go
@@ -0,0 +1,35 @@
+/*
+ * 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 flows
+
+import (
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
+)
+
+const (
+ logLevel = log.ErrorLevel
+)
+
+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, logLevel, log.Fields{"pkg": "flowsUtils"})
+ if err != nil {
+ panic(err)
+ }
+}
diff --git a/pkg/flows/flow_utils.go b/pkg/flows/flow_utils.go
index 02a4b0b..d3cf74d 100644
--- a/pkg/flows/flow_utils.go
+++ b/pkg/flows/flow_utils.go
@@ -510,7 +510,7 @@
return uint32(field.GetTableMetadata() & 0xFFFFFFFF)
}
}
- log.Debug("No-metadata-present")
+ logger.Debug("No-metadata-present")
return 0
}
@@ -523,7 +523,7 @@
return field.GetTableMetadata()
}
}
- log.Debug("No-metadata-present")
+ logger.Debug("No-metadata-present")
return 0
}
@@ -538,7 +538,7 @@
}
}
}
- log.Debugw("No-write-metadata-present", log.Fields{"flow": flow})
+ logger.Debugw("No-write-metadata-present", log.Fields{"flow": flow})
return 0
}
@@ -552,10 +552,10 @@
This is set in the ONOS OltPipeline as a write metadata instruction
*/
var tpId uint16 = 0
- log.Debugw("Write metadata value for Techprofile ID", log.Fields{"metadata": metadata})
+ logger.Debugw("Write metadata value for Techprofile ID", log.Fields{"metadata": metadata})
if metadata != 0 {
tpId = uint16((metadata >> 32) & 0xFFFF)
- log.Debugw("Found techprofile ID from write metadata action", log.Fields{"tpid": tpId})
+ logger.Debugw("Found techprofile ID from write metadata action", log.Fields{"tpid": tpId})
}
return tpId
}
@@ -570,10 +570,10 @@
*/
var uniPort uint32 = 0
md := GetMetadataFromWriteMetadataAction(flow)
- log.Debugw("Metadata found for egress/uni port ", log.Fields{"metadata": md})
+ logger.Debugw("Metadata found for egress/uni port ", log.Fields{"metadata": md})
if md != 0 {
uniPort = uint32(md & 0xFFFFFFFF)
- log.Debugw("Found EgressPort from write metadata action", log.Fields{"egress_port": uniPort})
+ logger.Debugw("Found EgressPort from write metadata action", log.Fields{"egress_port": uniPort})
}
return uniPort
@@ -591,7 +591,7 @@
md := GetMetadataFromWriteMetadataAction(flow)
if md != 0 {
innerTag = uint16((md >> 48) & 0xFFFF)
- log.Debugw("Found CVLAN from write metadate action", log.Fields{"c_vlan": innerTag})
+ logger.Debugw("Found CVLAN from write metadate action", log.Fields{"c_vlan": innerTag})
}
return innerTag
}
@@ -605,7 +605,7 @@
return 0
}
if md <= 0xffffffff {
- log.Debugw("onos-upgrade-suggested", log.Fields{"Metadata_ofp": md, "message": "Legacy MetaData detected form OltPipeline"})
+ logger.Debugw("onos-upgrade-suggested", logger.Fields{"Metadata_ofp": md, "message": "Legacy MetaData detected form OltPipeline"})
return md
}
return (md >> 32) & 0xffffffff
@@ -730,7 +730,7 @@
meter := &ofp.OfpMeterEntry{Config: &ofp.OfpMeterConfig{},
Stats: &ofp.OfpMeterStats{BandStats: bandStats}}
if meterMod == nil {
- log.Error("Invalid meter mod command")
+ logger.Error("Invalid meter mod command")
return meter
}
// config init
@@ -752,7 +752,7 @@
bandStats = append(bandStats, band)
}
meter.Stats.BandStats = bandStats
- log.Debugw("Allocated meter entry", log.Fields{"meter": *meter})
+ logger.Debugw("Allocated meter entry", log.Fields{"meter": *meter})
return meter
}
diff --git a/pkg/flows/flow_utils_test.go b/pkg/flows/flow_utils_test.go
index 8922a9c..a9dc9cc 100644
--- a/pkg/flows/flow_utils_test.go
+++ b/pkg/flows/flow_utils_test.go
@@ -17,7 +17,6 @@
import (
"bytes"
- "github.com/opencord/voltha-lib-go/v2/pkg/log"
ofp "github.com/opencord/voltha-protos/v2/go/openflow_13"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
@@ -32,7 +31,6 @@
)
func init() {
- log.AddPackage(log.JSON, log.WarnLevel, nil)
timeoutError = status.Errorf(codes.Aborted, "timeout")
taskFailureError = status.Error(codes.Internal, "test failure task")
timeoutError = status.Errorf(codes.Aborted, "timeout")