[VOL-3424] Switch completely to Context based Logger instance
Change-Id: I394ec682d4a8237740612de95826668e109f84b4
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
}