Skip to content

Commit

Permalink
Merge pull request #10021 from jingyih/add_log_level_checking_in_logg…
Browse files Browse the repository at this point in the history
…ing_interceptor

etcdserver/api/v3rpc/interceptor: add log level checking
  • Loading branch information
gyuho authored Aug 18, 2018
2 parents 6890a9e + 8d85259 commit 0a25f49
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion etcdserver/api/v3rpc/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 0a25f49

Please sign in to comment.