-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix zap grpclogger verbosity check (#366)
* Fix zap grpclogger verbosity check Currently it only logs entries that are *lower* or equal to the configured level, when you want the opposite. This means that by default only INFO messages are logged, and anything more urgent is dropped. * Add test verifying V method works as intended
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} |