diff --git a/logging/zap/grpclogger.go b/logging/zap/grpclogger.go index c3fafcc19..42842c991 100644 --- a/logging/zap/grpclogger.go +++ b/logging/zap/grpclogger.go @@ -114,5 +114,5 @@ func (l *zapGrpcLoggerV2) Fatalf(format string, args ...interface{}) { } func (l *zapGrpcLoggerV2) V(level int) bool { - return level <= l.verbosity + return l.verbosity <= level } diff --git a/logging/zap/grpclogger_test.go b/logging/zap/grpclogger_test.go new file mode 100644 index 000000000..aa8edf2f7 --- /dev/null +++ b/logging/zap/grpclogger_test.go @@ -0,0 +1,33 @@ +package grpc_zap + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "go.uber.org/zap/zaptest/observer" + "google.golang.org/grpc/grpclog" +) + +func Test_zapGrpcLogger_V(t *testing.T) { + // copied from gRPC + const ( + // infoLog indicates Info severity. + infoLog int = iota + // warningLog indicates Warning severity. + warningLog + // errorLog indicates Error severity. + errorLog + // fatalLog indicates Fatal severity. + fatalLog + ) + + core, _ := observer.New(zapcore.DebugLevel) + logger := zap.New(core) + ReplaceGrpcLoggerV2WithVerbosity(logger, warningLog) + assert.False(t, grpclog.V(infoLog)) + assert.True(t, grpclog.V(warningLog)) + assert.True(t, grpclog.V(errorLog)) + assert.True(t, grpclog.V(fatalLog)) +}