[VOL-3424] Switch completely to Context based Logger instance
Change-Id: I3327f08c5f3910f25aaca27c937026c050befca3
diff --git a/VERSION b/VERSION
index 34cde56..2058d31 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.2.6
+3.2.7-dev
diff --git a/pkg/log/common.go b/pkg/log/common.go
new file mode 100644
index 0000000..b0ce81b
--- /dev/null
+++ b/pkg/log/common.go
@@ -0,0 +1,27 @@
+/*
+ * 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 log
+
+var logger CLogger
+
+func init() {
+ // Setup this package so that it's log level can be modified at run time
+ var err error
+ logger, err = RegisterPackage(JSON, ErrorLevel, Fields{})
+ if err != nil {
+ panic(err)
+ }
+}
diff --git a/pkg/log/log.go b/pkg/log/log.go
index 1e23da1..62a232e 100644
--- a/pkg/log/log.go
+++ b/pkg/log/log.go
@@ -14,29 +14,39 @@
* limitations under the License.
*/
-//Package log provides a structured Logger interface implemented using zap logger. It provides the following capabilities:
-//1. Package level logging - a go package can register itself (AddPackage) and have a logger created for that package.
-//2. Dynamic log level change - for all registered packages (SetAllLogLevel)
-//3. Dynamic log level change - for a given package (SetPackageLogLevel)
-//4. Provides a default logger for unregistered packages
-//5. Allow key-value pairs to be added to a logger(UpdateLogger) or all loggers (UpdateAllLoggers) at run time
-//6. Add to the log output the location where the log was invoked (filename.functionname.linenumber)
+// Package log provides a structured Logger interface implemented using zap logger. It provides the following capabilities:
+// 1. Package level logging - a go package can register itself (AddPackage) and have a logger created for that package.
+// 2. Dynamic log level change - for all registered packages (SetAllLogLevel)
+// 3. Dynamic log level change - for a given package (SetPackageLogLevel)
+// 4. Provides a default logger for unregistered packages (however avoid its usage)
+// 5. Allow key-value pairs to be added to a logger(UpdateLogger) or all loggers (UpdateAllLoggers) at run time
+// 6. Add to the log output the location where the log was invoked (filename.functionname.linenumber)
//
// Using package-level logging (recommended approach). In the examples below, log refers to this log package.
-// 1. In the appropriate package add the following in the init section of the package. The log level can be changed
-// and any number of default fields can be added as well. The log level specifies the lowest log level that will be
-// in the output while the fields will be automatically added to all log printouts.
//
-// log.AddPackage(mylog.JSON, log.WarnLevel, log.Fields{"anyFieldName": "any value"})
+// 1. In the appropriate package, add the following in the init section of the package (usually in a common.go file)
+// The log level can be changed and any number of default fields can be added as well. The log level specifies
+// the lowest log level that will be in the output while the fields will be automatically added to all log printouts.
+// However, as voltha components re-initialize the log level of each registered package to default initial loglevel
+// passed as CLI argument, the log level passed in RegisterPackage call effectively has no effect.
//
-//2. In the calling package, just invoke any of the publicly available functions of the logger. Here is an example
-// to write an Info log with additional fields:
+// var logger log.CLogger
+// func init() {
+// logger, err = log.RegisterPackage(log.JSON, log.ErrorLevel, log.Fields{"key1": "value1"})
+// }
//
-//log.Infow("An example", mylog.Fields{"myStringOutput": "output", "myIntOutput": 2})
+// 2. In the calling package, use any of the publicly available functions of local package-level logger instance created
+// in previous step. Here is an example to write an Info log with additional fields:
//
-//3. To dynamically change the log level, you can use 1)SetLogLevel from inside your package or 2) SetPackageLogLevel
-// from anywhere or 3) SetAllLogLevel from anywhere.
+// logger.Infow("An example", mylog.Fields{"myStringOutput": "output", "myIntOutput": 2})
//
+// 3. To dynamically change the log level, you can use
+// a) SetLogLevel from inside your package or
+// b) SetPackageLogLevel from anywhere or
+// c) SetAllLogLevel from anywhere.
+//
+// Dynamic Loglevel configuration feature also uses SetPackageLogLevel method based on triggers received due to
+// Changes to configured loglevels
package log
diff --git a/pkg/log/log_classic.go b/pkg/log/log_classic.go
deleted file mode 100644
index b47b562..0000000
--- a/pkg/log/log_classic.go
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- * Copyright 2018-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.
- */
-
-// Older Version of Logger interface without support of Context Injection
-// This is Depreciated and should not be used anymore. Instead use CLogger
-// defined in log.go file.
-// This file will be deleted once all code files of voltha compopnents have been
-// changed to use new CLogger interface methods supporting context injection
-package log
-
-import (
- zp "go.uber.org/zap"
-)
-
-// Logger represents an abstract logging interface. Any logging implementation used
-// will need to abide by this interface
-type Logger interface {
- Debug(...interface{})
- Debugln(...interface{})
- Debugf(string, ...interface{})
- Debugw(string, Fields)
-
- Info(...interface{})
- Infoln(...interface{})
- Infof(string, ...interface{})
- Infow(string, Fields)
-
- Warn(...interface{})
- Warnln(...interface{})
- Warnf(string, ...interface{})
- Warnw(string, Fields)
-
- Error(...interface{})
- Errorln(...interface{})
- Errorf(string, ...interface{})
- Errorw(string, Fields)
-
- Fatal(...interface{})
- Fatalln(...interface{})
- Fatalf(string, ...interface{})
- Fatalw(string, Fields)
-
- With(Fields) Logger
-
- // The following are added to be able to use this logger as a gRPC LoggerV2 if needed
- //
- Warning(...interface{})
- Warningln(...interface{})
- Warningf(string, ...interface{})
-
- // V reports whether verbosity level l is at least the requested verbose level.
- V(l LogLevel) bool
-
- //Returns the log level of this specific logger
- GetLogLevel() LogLevel
-}
-
-// logger has been refactored to be a thin wrapper on clogger implementation to support
-// all existing log statements during transition to new clogger
-type logger struct {
- cl *clogger
-}
-
-func AddPackage(outputType string, level LogLevel, defaultFields Fields, pkgNames ...string) (Logger, error) {
- // Get package name of caller method and pass further on; else this method is considered caller
- pkgName, _, _, _ := getCallerInfo()
-
- pkgNames = append(pkgNames, pkgName)
- clg, err := RegisterPackage(outputType, level, defaultFields, pkgNames...)
- if err != nil {
- return nil, err
- }
-
- return logger{cl: clg.(*clogger)}, nil
-}
-
-func getPackageLevelSugaredLogger() *zp.SugaredLogger {
- pkgName, _, _, _ := getCallerInfo()
- if _, exist := loggers[pkgName]; exist {
- return loggers[pkgName].log
- }
- return defaultLogger.log
-}
-
-func getPackageLevelLogger() CLogger {
- pkgName, _, _, _ := getCallerInfo()
- if _, exist := loggers[pkgName]; exist {
- return loggers[pkgName]
- }
- return defaultLogger
-}
-
-// With returns a logger initialized with the key-value pairs
-func (l logger) With(keysAndValues Fields) Logger {
- return logger{cl: &clogger{log: l.cl.log.With(serializeMap(keysAndValues)...), parent: l.cl.parent}}
-}
-
-// Debug logs a message at level Debug on the standard logger.
-func (l logger) Debug(args ...interface{}) {
- l.cl.log.Debug(args...)
-}
-
-// Debugln logs a message at level Debug on the standard logger with a line feed. Default in any case.
-func (l logger) Debugln(args ...interface{}) {
- l.cl.log.Debug(args...)
-}
-
-// Debugw logs a message at level Debug on the standard logger.
-func (l logger) Debugf(format string, args ...interface{}) {
- l.cl.log.Debugf(format, args...)
-}
-
-// Debugw logs a message with some additional context. The variadic key-value
-// pairs are treated as they are in With.
-func (l logger) Debugw(msg string, keysAndValues Fields) {
- if l.V(DebugLevel) {
- l.cl.log.Debugw(msg, serializeMap(keysAndValues)...)
- }
-}
-
-// Info logs a message at level Info on the standard logger.
-func (l logger) Info(args ...interface{}) {
- l.cl.log.Info(args...)
-}
-
-// Infoln logs a message at level Info on the standard logger with a line feed. Default in any case.
-func (l logger) Infoln(args ...interface{}) {
- l.cl.log.Info(args...)
- //msg := fmt.Sprintln(args...)
- //l.sourced().Info(msg[:len(msg)-1])
-}
-
-// Infof logs a message at level Info on the standard logger.
-func (l logger) Infof(format string, args ...interface{}) {
- l.cl.log.Infof(format, args...)
-}
-
-// Infow logs a message with some additional context. The variadic key-value
-// pairs are treated as they are in With.
-func (l logger) Infow(msg string, keysAndValues Fields) {
- if l.V(InfoLevel) {
- l.cl.log.Infow(msg, serializeMap(keysAndValues)...)
- }
-}
-
-// Warn logs a message at level Warn on the standard logger.
-func (l logger) Warn(args ...interface{}) {
- l.cl.log.Warn(args...)
-}
-
-// Warnln logs a message at level Warn on the standard logger with a line feed. Default in any case.
-func (l logger) Warnln(args ...interface{}) {
- l.cl.log.Warn(args...)
-}
-
-// Warnf logs a message at level Warn on the standard logger.
-func (l logger) Warnf(format string, args ...interface{}) {
- l.cl.log.Warnf(format, args...)
-}
-
-// Warnw logs a message with some additional context. The variadic key-value
-// pairs are treated as they are in With.
-func (l logger) Warnw(msg string, keysAndValues Fields) {
- if l.V(WarnLevel) {
- l.cl.log.Warnw(msg, serializeMap(keysAndValues)...)
- }
-}
-
-// Error logs a message at level Error on the standard logger.
-func (l logger) Error(args ...interface{}) {
- l.cl.log.Error(args...)
-}
-
-// Errorln logs a message at level Error on the standard logger with a line feed. Default in any case.
-func (l logger) Errorln(args ...interface{}) {
- l.cl.log.Error(args...)
-}
-
-// Errorf logs a message at level Error on the standard logger.
-func (l logger) Errorf(format string, args ...interface{}) {
- l.cl.log.Errorf(format, args...)
-}
-
-// Errorw logs a message with some additional context. The variadic key-value
-// pairs are treated as they are in With.
-func (l logger) Errorw(msg string, keysAndValues Fields) {
- if l.V(ErrorLevel) {
- l.cl.log.Errorw(msg, serializeMap(keysAndValues)...)
- }
-}
-
-// Fatal logs a message at level Fatal on the standard logger.
-func (l logger) Fatal(args ...interface{}) {
- l.cl.log.Fatal(args...)
-}
-
-// Fatalln logs a message at level Fatal on the standard logger with a line feed. Default in any case.
-func (l logger) Fatalln(args ...interface{}) {
- l.cl.log.Fatal(args...)
-}
-
-// Fatalf logs a message at level Fatal on the standard logger.
-func (l logger) Fatalf(format string, args ...interface{}) {
- l.cl.log.Fatalf(format, args...)
-}
-
-// Fatalw logs a message with some additional context. The variadic key-value
-// pairs are treated as they are in With.
-func (l logger) Fatalw(msg string, keysAndValues Fields) {
- if l.V(FatalLevel) {
- l.cl.log.Fatalw(msg, serializeMap(keysAndValues)...)
- }
-}
-
-// Warning logs a message at level Warn on the standard logger.
-func (l logger) Warning(args ...interface{}) {
- l.cl.log.Warn(args...)
-}
-
-// Warningln logs a message at level Warn on the standard logger with a line feed. Default in any case.
-func (l logger) Warningln(args ...interface{}) {
- l.cl.log.Warn(args...)
-}
-
-// Warningf logs a message at level Warn on the standard logger.
-func (l logger) Warningf(format string, args ...interface{}) {
- l.cl.log.Warnf(format, args...)
-}
-
-// V reports whether verbosity level l is at least the requested verbose level.
-func (l logger) V(level LogLevel) bool {
- return l.cl.parent.Core().Enabled(logLevelToLevel(level))
-}
-
-// GetLogLevel returns the current level of the logger
-func (l logger) GetLogLevel() LogLevel {
- return levelToLogLevel(cfgs[l.cl.packageName].Level.Level())
-}
-
-// With returns a logger initialized with the key-value pairs
-func With(keysAndValues Fields) Logger {
- return logger{cl: &clogger{log: getPackageLevelSugaredLogger().With(serializeMap(keysAndValues)...), parent: defaultLogger.parent}}
-}
-
-// Debug logs a message at level Debug on the standard logger.
-func Debug(args ...interface{}) {
- getPackageLevelSugaredLogger().Debug(args...)
-}
-
-// Debugln logs a message at level Debug on the standard logger.
-func Debugln(args ...interface{}) {
- getPackageLevelSugaredLogger().Debug(args...)
-}
-
-// Debugf logs a message at level Debug on the standard logger.
-func Debugf(format string, args ...interface{}) {
- getPackageLevelSugaredLogger().Debugf(format, args...)
-}
-
-// Debugw logs a message with some additional context. The variadic key-value
-// pairs are treated as they are in With.
-func Debugw(msg string, keysAndValues Fields) {
- getPackageLevelSugaredLogger().Debugw(msg, serializeMap(keysAndValues)...)
-}
-
-// Info logs a message at level Info on the standard logger.
-func Info(args ...interface{}) {
- getPackageLevelSugaredLogger().Info(args...)
-}
-
-// Infoln logs a message at level Info on the standard logger.
-func Infoln(args ...interface{}) {
- getPackageLevelSugaredLogger().Info(args...)
-}
-
-// Infof logs a message at level Info on the standard logger.
-func Infof(format string, args ...interface{}) {
- getPackageLevelSugaredLogger().Infof(format, args...)
-}
-
-//Infow logs a message with some additional context. The variadic key-value
-//pairs are treated as they are in With.
-func Infow(msg string, keysAndValues Fields) {
- getPackageLevelSugaredLogger().Infow(msg, serializeMap(keysAndValues)...)
-}
-
-// Warn logs a message at level Warn on the standard logger.
-func Warn(args ...interface{}) {
- getPackageLevelSugaredLogger().Warn(args...)
-}
-
-// Warnln logs a message at level Warn on the standard logger.
-func Warnln(args ...interface{}) {
- getPackageLevelSugaredLogger().Warn(args...)
-}
-
-// Warnf logs a message at level Warn on the standard logger.
-func Warnf(format string, args ...interface{}) {
- getPackageLevelSugaredLogger().Warnf(format, args...)
-}
-
-// Warnw logs a message with some additional context. The variadic key-value
-// pairs are treated as they are in With.
-func Warnw(msg string, keysAndValues Fields) {
- getPackageLevelSugaredLogger().Warnw(msg, serializeMap(keysAndValues)...)
-}
-
-// Error logs a message at level Error on the standard logger.
-func Error(args ...interface{}) {
- getPackageLevelSugaredLogger().Error(args...)
-}
-
-// Errorln logs a message at level Error on the standard logger.
-func Errorln(args ...interface{}) {
- getPackageLevelSugaredLogger().Error(args...)
-}
-
-// Errorf logs a message at level Error on the standard logger.
-func Errorf(format string, args ...interface{}) {
- getPackageLevelSugaredLogger().Errorf(format, args...)
-}
-
-// Errorw logs a message with some additional context. The variadic key-value
-// pairs are treated as they are in With.
-func Errorw(msg string, keysAndValues Fields) {
- getPackageLevelSugaredLogger().Errorw(msg, serializeMap(keysAndValues)...)
-}
-
-// Fatal logs a message at level Fatal on the standard logger.
-func Fatal(args ...interface{}) {
- getPackageLevelSugaredLogger().Fatal(args...)
-}
-
-// Fatalln logs a message at level Fatal on the standard logger.
-func Fatalln(args ...interface{}) {
- getPackageLevelSugaredLogger().Fatal(args...)
-}
-
-// Fatalf logs a message at level Fatal on the standard logger.
-func Fatalf(format string, args ...interface{}) {
- getPackageLevelSugaredLogger().Fatalf(format, args...)
-}
-
-// Fatalw logs a message with some additional context. The variadic key-value
-// pairs are treated as they are in With.
-func Fatalw(msg string, keysAndValues Fields) {
- getPackageLevelSugaredLogger().Fatalw(msg, serializeMap(keysAndValues)...)
-}
-
-// Warning logs a message at level Warn on the standard logger.
-func Warning(args ...interface{}) {
- getPackageLevelSugaredLogger().Warn(args...)
-}
-
-// Warningln logs a message at level Warn on the standard logger.
-func Warningln(args ...interface{}) {
- getPackageLevelSugaredLogger().Warn(args...)
-}
-
-// Warningf logs a message at level Warn on the standard logger.
-func Warningf(format string, args ...interface{}) {
- getPackageLevelSugaredLogger().Warnf(format, args...)
-}
-
-// V reports whether verbosity level l is at least the requested verbose level.
-func V(level LogLevel) bool {
- return getPackageLevelLogger().V(level)
-}
-
-//GetLogLevel returns the log level of the invoking package
-func GetLogLevel() LogLevel {
- return getPackageLevelLogger().GetLogLevel()
-}
diff --git a/pkg/log/log_test.go b/pkg/log/log_test.go
index 121829e..bc78dfe 100644
--- a/pkg/log/log_test.go
+++ b/pkg/log/log_test.go
@@ -24,11 +24,11 @@
Prerequite: Start the kafka/zookeeper containers.
*/
-var testLogger Logger
+var testLogger CLogger
func TestInit(t *testing.T) {
var err error
- testLogger, err = AddPackage(JSON, ErrorLevel, nil)
+ testLogger, err = RegisterPackage(JSON, ErrorLevel, nil)
assert.NotNil(t, testLogger)
assert.Nil(t, err)
}
@@ -69,10 +69,10 @@
func TestUpdateLogLevel(t *testing.T) {
// Let's create a bunch of logger each with a separate package
- myLoggers := make(map[string]Logger)
+ myLoggers := make(map[string]CLogger)
pkgNames := []string{"/rw_core/core", "/db/model", "/kafka"}
for _, name := range pkgNames {
- myLoggers[name], _ = AddPackage(JSON, ErrorLevel, nil, []string{name}...)
+ myLoggers[name], _ = RegisterPackage(JSON, ErrorLevel, nil, []string{name}...)
}
//Test updates to log levels
levels := []LogLevel{DebugLevel, InfoLevel, WarnLevel, ErrorLevel, FatalLevel}
diff --git a/pkg/log/utils.go b/pkg/log/utils.go
index b22ca14..03e6fd7 100644
--- a/pkg/log/utils.go
+++ b/pkg/log/utils.go
@@ -60,14 +60,14 @@
// terminate tracing on component shutdown
func InitTracingAndLogCorrelation(tracePublishEnabled bool, traceAgentAddress string, logCorrelationEnabled bool) (io.Closer, error) {
if !tracePublishEnabled && !logCorrelationEnabled {
- defaultLogger.Info(context.Background(), "Skipping Global Tracer initialization as both Trace publish and Log correlation are configured as disabled")
+ logger.Info(context.Background(), "Skipping Global Tracer initialization as both Trace publish and Log correlation are configured as disabled")
extractLogFieldsFromContext = false
processSpanOperations = false
return ioutil.NopCloser(strings.NewReader("")), nil
}
if !logCorrelationEnabled {
- defaultLogger.Info(context.Background(), "Disabling Log Fields extraction from context as configured")
+ logger.Info(context.Background(), "Disabling Log Fields extraction from context as configured")
extractLogFieldsFromContext = false
}
@@ -86,10 +86,10 @@
// Attempt Trace Agent Address only if Trace Publishing is enabled; else directly use Loopback IP
if tracePublishEnabled {
jReporterConfig = jcfg.ReporterConfig{LocalAgentHostPort: traceAgentAddress, LogSpans: true}
- jReporterCfgOption, err = jReporterConfig.NewReporter(componentName, jtracing.NewNullMetrics(), traceLogger{logger: defaultLogger})
+ jReporterCfgOption, err = jReporterConfig.NewReporter(componentName, jtracing.NewNullMetrics(), traceLogger{logger: logger.(*clogger)})
if err != nil {
- defaultLogger.Errorw(context.Background(), "Unable to create Reporter with given Trace Agent address",
+ logger.Errorw(context.Background(), "Unable to create Reporter with given Trace Agent address",
Fields{"error": err, "address": traceAgentAddress})
// The Reporter initialization may fail due to Invalid Agent address or non-existent Agent (DNS lookup failure).
// It is essential for Tracer Instance to still start for correct Span propagation needed for log correlation.
@@ -100,7 +100,7 @@
if !tracePublishEnabled {
jReporterConfig.LocalAgentHostPort = "127.0.0.1:6831"
- jReporterCfgOption, err = jReporterConfig.NewReporter(componentName, jtracing.NewNullMetrics(), traceLogger{logger: defaultLogger})
+ jReporterCfgOption, err = jReporterConfig.NewReporter(componentName, jtracing.NewNullMetrics(), traceLogger{logger: logger.(*clogger)})
if err != nil {
return nil, errors.New("Failed to initialize Jaeger Tracing due to Reporter creation error : " + err.Error())
}
@@ -123,7 +123,7 @@
func TerminateTracing(c io.Closer) {
err := c.Close()
if err != nil {
- defaultLogger.Error(context.Background(), "error-while-closing-jaeger-tracer", Fields{"err": err})
+ logger.Error(context.Background(), "error-while-closing-jaeger-tracer", Fields{"err": err})
}
}
@@ -265,7 +265,7 @@
// We should always be creating Aysnc span from a Valid parent span. If not, create a Child span instead
if parentSpan == nil {
- defaultLogger.Warn(context.Background(), "Async span must be created with a Valid parent span only")
+ logger.Warn(context.Background(), "Async span must be created with a Valid parent span only")
asyncSpan, newCtx = opentracing.StartSpanFromContext(ctx, taskName)
} else {
// Use Background context as the base for Follows-from case; else new span is getting both Child and FollowsFrom relationship
diff --git a/pkg/techprofile/tech_profile.go b/pkg/techprofile/tech_profile.go
index a12df1d..13cd081 100644
--- a/pkg/techprofile/tech_profile.go
+++ b/pkg/techprofile/tech_profile.go
@@ -454,7 +454,7 @@
case epon:
resPtr = &KvEponIns
default:
- log.Errorw("unknown-tech", log.Fields{"tech": pathSlice[0]})
+ logger.Errorw(ctx, "unknown-tech", log.Fields{"tech": pathSlice[0]})
return nil, fmt.Errorf("unknown-tech-%s", pathSlice[0])
}
@@ -572,13 +572,13 @@
if tp != nil {
if err := t.validateInstanceControlAttr(ctx, tp.InstanceCtrl); err != nil {
logger.Error(ctx, "invalid-instance-ctrl-attr--using-default-tp")
- tp = t.getDefaultEponProfile()
+ tp = t.getDefaultEponProfile(ctx)
} else {
logger.Infow(ctx, "using-specified-tp-from-kv-store", log.Fields{"tpid": techProfiletblID})
}
} else {
logger.Info(ctx, "tp-not-found-on-kv--creating-default-tp")
- tp = t.getDefaultEponProfile()
+ tp = t.getDefaultEponProfile(ctx)
}
if tpEponInstance = t.allocateEponTPInstance(ctx, uniPortName, tp, intfId, tpInstancePath); tpEponInstance == nil {
@@ -788,22 +788,22 @@
var gemPorts []uint32
var err error
- log.Infow("Allocating TechProfileMgr instance from techprofile template", log.Fields{"uniPortName": uniPortName, "intfId": intfId, "numGem": tp.NumGemPorts})
+ logger.Infow(ctx, "Allocating TechProfileMgr instance from techprofile template", log.Fields{"uniPortName": uniPortName, "intfId": intfId, "numGem": tp.NumGemPorts})
if tp.InstanceCtrl.Onu == "multi-instance" {
if tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1); err != nil {
- log.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
+ logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
return nil
}
} else { // "single-instance"
if tpInst, err := t.getSingleInstanceEponTp(ctx, tpInstPath); err != nil {
- log.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
+ logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
return nil
} else if tpInst == nil {
// No "single-instance" tp found on one any uni port for the given TP ID
// Allocate a new TcontID or AllocID
if tcontIDs, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeAllocID(), 1); err != nil {
- log.Errorw("Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
+ logger.Errorw(ctx, "Error getting alloc id from rsrcrMgr", log.Fields{"intfId": intfId})
return nil
}
} else {
@@ -811,12 +811,12 @@
tcontIDs = append(tcontIDs, tpInst.AllocID)
}
}
- log.Debugw("Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts})
+ logger.Debugw(ctx, "Num GEM ports in TP:", log.Fields{"NumGemPorts": tp.NumGemPorts})
if gemPorts, err = t.resourceMgr.GetResourceID(ctx, intfId, t.resourceMgr.GetResourceTypeGemPortID(), tp.NumGemPorts); err != nil {
- log.Errorw("Error getting gemport ids from rsrcrMgr", log.Fields{"intfId": intfId, "numGemports": tp.NumGemPorts})
+ logger.Errorw(ctx, "Error getting gemport ids from rsrcrMgr", log.Fields{"intfId": intfId, "numGemports": tp.NumGemPorts})
return nil
}
- log.Infow("Allocated tconts and GEM ports successfully", log.Fields{"tconts": tcontIDs, "gemports": gemPorts})
+ logger.Infow(ctx, "Allocated tconts and GEM ports successfully", log.Fields{"tconts": tcontIDs, "gemports": gemPorts})
for index := 0; index < int(tp.NumGemPorts); index++ {
usQueueAttributeList = append(usQueueAttributeList,
iUpstreamQueueAttribute{GemportID: gemPorts[index],
@@ -837,7 +837,7 @@
DiscardConfig: tp.UpstreamQueueAttributeList[index].DiscardConfig})
}
- log.Info("length of DownstreamGemPortAttributeList", len(tp.DownstreamQueueAttributeList))
+ logger.Info(ctx, "length of DownstreamGemPortAttributeList", len(tp.DownstreamQueueAttributeList))
for index := 0; index < int(tp.NumGemPorts); index++ {
dsQueueAttributeList = append(dsQueueAttributeList,
iDownstreamQueueAttribute{GemportID: gemPorts[index],
@@ -977,13 +977,13 @@
}
// getDefaultTechProfile function for EPON
-func (t *TechProfileMgr) getDefaultEponProfile() *DefaultEponProfile {
+func (t *TechProfileMgr) getDefaultEponProfile(ctx context.Context) *DefaultEponProfile {
var usQueueAttributeList []UpstreamQueueAttribute
var dsQueueAttributeList []DownstreamQueueAttribute
for _, pbit := range t.config.DefaultPbits {
- log.Debugw("Creating Queue", log.Fields{"pbit": pbit})
+ logger.Debugw(ctx, "Creating Queue", log.Fields{"pbit": pbit})
usQueueAttributeList = append(usQueueAttributeList,
UpstreamQueueAttribute{
MaxQueueSize: defaultMaxQueueSize,
@@ -1389,7 +1389,7 @@
case epon:
return tpInstancesEpon
default:
- log.Errorw("unknown-technology", log.Fields{"tech": tech})
+ logger.Errorw(ctx, "unknown-technology", log.Fields{"tech": tech})
return nil
}
}