Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert verbosity level check for zap #452

Merged
merged 1 commit into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion logging/zap/grpclogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,7 @@ func (l *zapGrpcLoggerV2) Fatalf(format string, args ...interface{}) {
}

func (l *zapGrpcLoggerV2) V(level int) bool {
return l.verbosity <= level
// Check whether the verbosity of the current log ('level') is within the specified threshold ('l.verbosity').
// As in https://github.com/grpc/grpc-go/blob/41e044e1c82fcf6a5801d6cbd7ecf952505eecb1/grpclog/loggerv2.go#L199-L201.
return level <= l.verbosity
}
29 changes: 15 additions & 14 deletions logging/zap/grpclogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ import (
)

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
// The default verbosity level.
// See https://github.com/grpc/grpc-go/blob/8ab16ef276a33df4cdb106446eeff40ff56a6928/grpclog/loggerv2.go#L108.
normal = 0

// Currently the only level of "being verbose".
// For example https://github.com/grpc/grpc-go/blob/8ab16ef276a33df4cdb106446eeff40ff56a6928/grpclog/grpclog.go#L21.
verbose = 2

// As is mentioned in https://github.com/grpc/grpc-go/blob/8ab16ef276a33df4cdb106446eeff40ff56a6928/README.md#how-to-turn-on-logging,
// though currently not being used in the code.
extremelyVerbose = 99
)

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))
ReplaceGrpcLoggerV2WithVerbosity(logger, verbose)
assert.True(t, grpclog.V(normal))
assert.True(t, grpclog.V(verbose))
assert.False(t, grpclog.V(extremelyVerbose))
}

func TestReplaceGrpcLoggerV2(t *testing.T) {
Expand Down