From 8d85259b561b884dcecf9ea79bffccf5f5013e26 Mon Sep 17 00:00:00 2001 From: Jingyi Hu Date: Fri, 17 Aug 2018 16:12:05 -0700 Subject: [PATCH] etcdserver/api/v3rpc/interceptor: add log level checking Check log level before generating and writing log info. --- etcdserver/api/v3rpc/interceptor.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/etcdserver/api/v3rpc/interceptor.go b/etcdserver/api/v3rpc/interceptor.go index 5265051ce52..cc095ef9cec 100644 --- a/etcdserver/api/v3rpc/interceptor.go +++ b/etcdserver/api/v3rpc/interceptor.go @@ -26,6 +26,7 @@ import ( "github.com/coreos/etcd/raft" pb "github.com/coreos/etcd/etcdserver/etcdserverpb" + "github.com/coreos/pkg/capnslog" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -64,7 +65,11 @@ func newLogUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerIntercepto return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { startTime := time.Now() resp, err := handler(ctx, req) - defer logUnaryRequestStats(ctx, s.Logger(), info, startTime, req, resp) + lg := s.Logger() + if (lg != nil && lg.Core().Enabled(zap.DebugLevel)) || // using zap logger and debug level is enabled + (lg == nil && plog.LevelAt(capnslog.DEBUG)) { // or, using capnslog and debug level is enabled + defer logUnaryRequestStats(ctx, lg, info, startTime, req, resp) + } return resp, err } }