Documentation ¶
Index ¶
- Variables
- func AddFields(ctx context.Context, fields map[string]interface{})
- func DurationToDurationField(duration time.Duration) (key string, value interface{})
- func DurationToTimeMillisField(duration time.Duration) (key string, value interface{})
- func Extract(ctx context.Context) map[string]interface{}
- func StreamClientInterceptor(log logr.Logger, opts ...Option) grpc.StreamClientInterceptor
- func StreamServerInterceptor(log logr.Logger, opts ...Option) grpc.StreamServerInterceptor
- func ToContext(ctx context.Context, callLog map[string]interface{}) context.Context
- func UnaryClientInterceptor(log logr.Logger, opts ...Option) grpc.UnaryClientInterceptor
- func UnaryServerInterceptor(log logr.Logger, opts ...Option) grpc.UnaryServerInterceptor
- type CodeToLevel
- type DurationToField
- type KlogLevel
- type Option
Constants ¶
This section is empty.
Variables ¶
var DefaultDurationToField = DurationToTimeMillisField
DefaultDurationToField is the default implementation of converting request duration to a log field (key and value).
Functions ¶
func DurationToDurationField ¶
DurationToDurationField uses the duration value to log the request duration.
func DurationToTimeMillisField ¶
DurationToTimeMillisField converts the duration to milliseconds and uses the key `grpc.time_ms`.
func Extract ¶
Extract takes the call-scoped logrus.Entry from ctx_logrus middleware.
If the ctx_logrus middleware wasn't used, a no-op `logrus.Entry` is returned. This makes it safe to use regardless.
func StreamClientInterceptor ¶
func StreamClientInterceptor(log logr.Logger, opts ...Option) grpc.StreamClientInterceptor
StreamClientInterceptor returns a new streaming client interceptor that optionally logs the execution of external gRPC calls.
func StreamServerInterceptor ¶
func StreamServerInterceptor(log logr.Logger, opts ...Option) grpc.StreamServerInterceptor
StreamServerInterceptor returns a new streaming server interceptor that adds fields to the context.
func ToContext ¶
ToContext adds the logrus.Entry to the context for extraction later. Returning the new context that has been created.
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(log logr.Logger, opts ...Option) grpc.UnaryClientInterceptor
UnaryClientInterceptor returns a new unary client interceptor that optionally logs the execution of external gRPC calls.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(log logr.Logger, opts ...Option) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptors that adds fields to the context.
Types ¶
type CodeToLevel ¶
CodeToLevel function defines the mapping between gRPC return codes and interceptor log level.
type DurationToField ¶
DurationToField function defines how to produce duration fields for logging
type KlogLevel ¶
type KlogLevel int
KlogLevel is the Klog Level type
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 to log levels for server side.
type Option ¶
type Option func(*options)
Option for options
func WithCodes ¶
func WithCodes(f grpc_logging.ErrorToCode) Option
WithCodes customizes the function for mapping errors to error codes.
func WithDecider ¶
func WithDecider(f grpc_logging.Decider) Option
WithDecider customizes the function for deciding if the gRPC interceptor logs should log.
func WithDurationField ¶
func WithDurationField(f DurationToField) Option
WithDurationField customizes the function for mapping request durations to Zap fields.
func WithLevels ¶
func WithLevels(f CodeToLevel) Option
WithLevels customizes the function for mapping gRPC return codes and interceptor log level statements.