Documentation
¶
Overview ¶
Package logr provides a small adapter required to use logr in logging gRPC middlewares. Please see examples for examples of use.
Example (InitializationWithCustomLevels) ¶
// Logger is used, allowing pre-definition of certain fields by the user.
logger := klog.NewKlogr()
// Shared options for the logger, with a custom gRPC code to log level function.
opts := []logging.Option{
logging.WithLevels(customFunc),
}
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
middleware.WithUnaryServerChain(
logging.UnaryServerInterceptor(grpclogr.InterceptorLogger(logger), opts...),
),
middleware.WithStreamServerChain(
logging.StreamServerInterceptor(grpclogr.InterceptorLogger(logger), opts...),
),
)
Example (InitializationWithDurationFieldOverride) ¶
// Logger is used, allowing pre-definition of certain fields by the user.
logger := klog.NewKlogr()
// Shared options for the logger, with a custom duration to log field function.
opts := []logging.Option{
logging.WithDurationField(customDurationToFields),
}
// Create a server, make sure we put the tags context before everything else.
_ = grpc.NewServer(
middleware.WithUnaryServerChain(
logging.UnaryServerInterceptor(grpclogr.InterceptorLogger(logger), opts...),
),
middleware.WithStreamServerChain(
logging.StreamServerInterceptor(grpclogr.InterceptorLogger(logger), opts...),
),
)
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.