[VOL-3069]Pass Context in methods which are performing logging and need the context
Change-Id: I3d9e1c3eff95d60dde46d44d16bed4805f7447f5
diff --git a/pkg/grpc/common.go b/pkg/grpc/common.go
index 17eeeaf..fa53542 100644
--- a/pkg/grpc/common.go
+++ b/pkg/grpc/common.go
@@ -19,12 +19,12 @@
"github.com/opencord/voltha-lib-go/v3/pkg/log"
)
-var logger log.Logger
+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.AddPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "grpc"})
+ logger, err = log.RegisterPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "grpc"})
if err != nil {
panic(err)
}
diff --git a/pkg/grpc/server.go b/pkg/grpc/server.go
index fa5c521..2bf7696 100644
--- a/pkg/grpc/server.go
+++ b/pkg/grpc/server.go
@@ -93,19 +93,19 @@
lis, err := net.Listen("tcp", s.address)
if err != nil {
- logger.Fatalf("failed to listen: %v", err)
+ logger.Fatalf(ctx, "failed to listen: %v", err)
}
if s.secure && s.GrpcSecurity != nil {
creds, err := credentials.NewServerTLSFromFile(s.CertFile, s.KeyFile)
if err != nil {
- logger.Fatalf("could not load TLS keys: %s", err)
+ logger.Fatalf(ctx, "could not load TLS keys: %s", err)
}
s.gs = grpc.NewServer(grpc.Creds(creds),
withServerUnaryInterceptor(s))
} else {
- logger.Info("starting-insecure-grpc-server")
+ logger.Info(ctx, "starting-insecure-grpc-server")
s.gs = grpc.NewServer(withServerUnaryInterceptor(s))
}
@@ -115,7 +115,7 @@
}
if err := s.gs.Serve(lis); err != nil {
- logger.Fatalf("failed to serve: %v\n", err)
+ logger.Fatalf(ctx, "failed to serve: %v\n", err)
}
}
@@ -138,7 +138,7 @@
handler grpc.UnaryHandler) (interface{}, error) {
if (s.probe != nil) && (!s.probe.IsReady()) {
- logger.Warnf("Grpc request received while not ready %v", req)
+ logger.Warnf(ctx, "Grpc request received while not ready %v", req)
return nil, status.Error(codes.Unavailable, "system is not ready")
}