Documentation ¶
Overview ¶
Package rpclog implements a gRPC logging middleware.
Index ¶
- Constants
- func AddField(ctx context.Context, key string, value interface{})
- func DefaultClientCodeToLevel(code codes.Code) log.Level
- func DefaultCodeToLevel(code codes.Code) log.Level
- func ReplaceGrpcLogger(logger log.Interface)
- func StreamClientInterceptor(ctx context.Context, opts ...Option) grpc.StreamClientInterceptor
- func StreamNamespaceHook(namespace string) hooks.StreamHandlerMiddleware
- func StreamServerInterceptor(ctx context.Context, opts ...Option) grpc.StreamServerInterceptor
- func UnaryClientInterceptor(ctx context.Context, opts ...Option) grpc.UnaryClientInterceptor
- func UnaryNamespaceHook(namespace string) hooks.UnaryHandlerMiddleware
- func UnaryServerInterceptor(ctx context.Context, opts ...Option) grpc.UnaryServerInterceptor
- type CodeToLevel
- type Option
Constants ¶
const NamespaceHook = "namespace"
Variables ¶
This section is empty.
Functions ¶
func AddField ¶
AddField adds a log field to the fields in the request context. Not safe for concurrent use.
func DefaultClientCodeToLevel ¶
DefaultClientCodeToLevel is the default implementation of gRPC return codes to log levels for client side.
func DefaultCodeToLevel ¶
DefaultCodeToLevel is the default implementation of gRPC return codes and interceptor log level for server side.
func ReplaceGrpcLogger ¶
ReplaceGrpcLogger sets the given log.Interface as a gRPC-level logger. This should be called *before* any other initialization, preferably from init() functions.
func StreamClientInterceptor ¶
func StreamClientInterceptor(ctx context.Context, opts ...Option) grpc.StreamClientInterceptor
StreamClientInterceptor returns a new streaming client interceptor that optionally logs the execution of external gRPC calls.
func StreamNamespaceHook ¶
func StreamNamespaceHook(namespace string) hooks.StreamHandlerMiddleware
StreamNamespaceHook adds the component namespace to the context of the stream.
func StreamServerInterceptor ¶
func StreamServerInterceptor(ctx context.Context, opts ...Option) grpc.StreamServerInterceptor
StreamServerInterceptor returns a new streaming server interceptor that adds the logger from the global context to the call context.
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(ctx context.Context, opts ...Option) grpc.UnaryClientInterceptor
UnaryClientInterceptor returns a new unary client interceptor that optionally logs the execution of external gRPC calls.
func UnaryNamespaceHook ¶
func UnaryNamespaceHook(namespace string) hooks.UnaryHandlerMiddleware
UnaryNamespaceHook adds the component namespace to the context of the unary call.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(ctx context.Context, opts ...Option) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptors that adds the logger from the global context to the call context.
Types ¶
type CodeToLevel ¶
CodeToLevel function defines the mapping between gRPC return codes and interceptor log level.
type Option ¶
type Option func(*options)
Option for the grpc logging interceptors
func WithCodes ¶
func WithCodes(f grpc_logging.ErrorToCode) Option
WithCodes customizes the function for mapping errors to error codes.
func WithIgnoreMethods ¶
WithIgnoreMethods sets a list of methods for which no log messages are printed on success.
func WithLevels ¶
func WithLevels(f CodeToLevel) Option
WithLevels customizes the function for mapping gRPC return codes and interceptor log level statements.