-
Notifications
You must be signed in to change notification settings - Fork 703
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate ZAP with SettableLoggerV2.
The settable_test.go is a good example of integration of testing harness with grpclogging using zaptest, that is canonical usecase for this infrastructure.
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
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
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,31 @@ | ||
package grpc_zap_test | ||
|
||
import ( | ||
"testing" | ||
|
||
grpc_logsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable" | ||
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap" | ||
"go.uber.org/zap/zaptest" | ||
) | ||
|
||
var grpc_logger grpc_logsettable.SettableLoggerV2 | ||
|
||
func init() { | ||
grpc_logger = grpc_logsettable.ReplaceGrpcLoggerV2() | ||
} | ||
|
||
func beforeTest(t testing.TB) { | ||
grpc_zap.SetGrpcLoggerV2(grpc_logger, zaptest.NewLogger(t)) | ||
t.Cleanup(func() { | ||
grpc_logger.Reset() | ||
}) | ||
} | ||
|
||
// This test illustrates setting up a testing harness that attributes | ||
// all grpc logs emitted during the test to the test-specific log. | ||
// | ||
// In case of test failure, only logs emitted by this testcase will be printed. | ||
func TestSpecificLogging(t *testing.T) { | ||
beforeTest(t) | ||
grpc_logger.Info("Test specific log-line") | ||
} |