Documentation ¶
Overview ¶
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.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SettableLoggerV2 ¶
type SettableLoggerV2 interface { grpclog.LoggerV2 // Sets given logger as the underlying implementation. Set(loggerv2 grpclog.LoggerV2) // Sets `discard` logger as the underlying implementation. Reset() }
SettableLoggerV2 is thread-safe.
Example (Init) ¶
package main import ( "io/ioutil" "os" grpc_logsettable "github.com/grpc-ecosystem/go-grpc-middleware/logging/settable" "google.golang.org/grpc/grpclog" ) func main() { 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") // Expected output: INFO: 2021/03/15 12:59:54 [Emitted log by l2] }
Output:
func ReplaceGrpcLoggerV2 ¶
func ReplaceGrpcLoggerV2() SettableLoggerV2
ReplaceGrpcLoggerV2 creates and configures SettableLoggerV2 as grpc logger.
Click to show internal directories.
Click to hide internal directories.