[VOL-2694] Use package specific logger instance in all log statements
Change-Id: Icf1cb5ade42e42179aed7731b767af2f52481e3d
diff --git a/rw_core/utils/common.go b/rw_core/utils/common.go
new file mode 100644
index 0000000..679788f
--- /dev/null
+++ b/rw_core/utils/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 utils common Logger initialization
+package utils
+
+import (
+ "github.com/opencord/voltha-lib-go/v3/pkg/log"
+)
+
+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, log.ErrorLevel, log.Fields{"pkg": "utils"})
+ if err != nil {
+ panic(err)
+ }
+}
diff --git a/rw_core/utils/core_utils.go b/rw_core/utils/core_utils.go
index bffd9c4..1030735 100644
--- a/rw_core/utils/core_utils.go
+++ b/rw_core/utils/core_utils.go
@@ -83,7 +83,7 @@
for {
req, ok := <-rq.queue
if !ok {
- log.Warnw("request-sequencer-queue-closed", log.Fields{"id": rq.queueID})
+ logger.Warnw("request-sequencer-queue-closed", log.Fields{"id": rq.queueID})
break
}
// If the request is waiting then closing the reqChnl will trigger the request to proceed. Otherwise,
diff --git a/rw_core/utils/core_utils_test.go b/rw_core/utils/core_utils_test.go
index 0457606..e55b38c 100644
--- a/rw_core/utils/core_utils_test.go
+++ b/rw_core/utils/core_utils_test.go
@@ -20,7 +20,6 @@
"testing"
"time"
- "github.com/opencord/voltha-lib-go/v3/pkg/log"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@@ -32,10 +31,6 @@
)
func init() {
- _, err := log.AddPackage(log.JSON, log.WarnLevel, nil)
- if err != nil {
- log.Errorw("unable-to-register-package-to-the-log-map", log.Fields{"error": err})
- }
timeoutError = status.Errorf(codes.Aborted, "timeout")
taskFailureError = status.Error(codes.Internal, "test failure task")
}