...

Source file src/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/settable_test.go

Documentation: github.com/grpc-ecosystem/go-grpc-middleware/logging/zap

     1  package grpc_zap_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	grpc_logsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable"
     7  	grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
     8  	"go.uber.org/zap/zaptest"
     9  )
    10  
    11  var grpc_logger grpc_logsettable.SettableLoggerV2
    12  
    13  func init() {
    14  	grpc_logger = grpc_logsettable.ReplaceGrpcLoggerV2()
    15  }
    16  
    17  func beforeTest(t testing.TB) {
    18  	grpc_zap.SetGrpcLoggerV2(grpc_logger, zaptest.NewLogger(t))
    19  
    20  	// Starting from go-1.15+ automated 'reset' can also be set:
    21  	// t.Cleanup(func() {
    22  	//     grpc_logger.Reset()
    23  	// })
    24  }
    25  
    26  // This test illustrates setting up a testing harness that attributes
    27  // all grpc logs emitted during the test to the test-specific log.
    28  //
    29  // In case of test failure, only logs emitted by this testcase will be printed.
    30  func TestSpecificLogging(t *testing.T) {
    31  	beforeTest(t)
    32  	grpc_logger.Info("Test specific log-line")
    33  }
    34  

View as plain text