...
Package grpc_logsettable
grpc_logsettable contains a thread-safe wrapper around grpc-logging
infrastructure.
The go-grpc assumes that logger can be only configured once as the `SetLoggerV2`
method is:
```Not mutex-protected, should be called before any gRPC functions.```
This package allows to supply parent logger once ("before any grpc"), but
later change underlying implementation in thread-safe way when needed.
It's in particular useful for testing, where each testcase might need its own
logger.
SettableLoggerV2 is thread-safe.
type SettableLoggerV2 interface {
grpclog.LoggerV2
Set(loggerv2 grpclog.LoggerV2)
Reset()
}
▾ Example (Init)
Code:
l1 := grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard)
l2 := grpclog.NewLoggerV2(os.Stdout, os.Stdout, os.Stdout)
settableLogger := grpc_logsettable.ReplaceGrpcLoggerV2()
grpclog.Info("Discarded by default")
settableLogger.Set(l1)
grpclog.Info("Discarded log by l1")
settableLogger.Set(l2)
grpclog.Info("Emitted log by l2")
func ReplaceGrpcLoggerV2() SettableLoggerV2
ReplaceGrpcLoggerV2 creates and configures SettableLoggerV2 as grpc logger.