Documentation ¶
Index ¶
- Variables
- func DefaultClientCodeToLevel(code codes.Code) logger.Level
- func DefaultCodeToLevel(code codes.Code) logger.Level
- func DefaultMessageProducer(ctx context.Context, msg string, level logger.Level, code codes.Code, ...)
- func DurationToDurationField(duration time.Duration) map[string]interface{}
- func DurationToTimeMillisField(duration time.Duration) ctxlog.Fields
- func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor
- func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor
- func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor
- func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor
- type CodeToLevel
- type DurationToField
- type MessageProducer
- type Option
Constants ¶
This section is empty.
Variables ¶
var ( // SystemField is used in every log statement made through grpc_zap. Can be overwritten before any initialization code. SystemField = ctxlog.NewFields("system", "grpc") // ServerField is used in every server-side log statement made through grpc_zap.Can be overwritten before initialization. ServerField = ctxlog.NewFields("span.kind", "server") )
var (
ClientField = ctxlog.NewFields("span.kind", "client")
)
var DefaultDurationToField = DurationToTimeMillisField
DefaultDurationToField is the default implementation of converting request duration to a Zap field.
Functions ¶
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 DefaultMessageProducer ¶
func DefaultMessageProducer(ctx context.Context, msg string, level logger.Level, code codes.Code, err error, duration ctxlog.Fields)
DefaultMessageProducer writes the default message
func DurationToDurationField ¶
DurationToDurationField uses a Duration field to log the request duration and leaves it up to Zap's encoder settings to determine how that is output.
func DurationToTimeMillisField ¶
DurationToTimeMillisField converts the duration to milliseconds and uses the key `grpc.time_ms`.
func StreamClientInterceptor ¶
func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor
StreamClientInterceptor returns a new streaming client interceptor that optionally logs the execution of external gRPC calls.
func StreamServerInterceptor ¶
func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor
StreamServerInterceptor returns a new streaming server interceptor that adds zap.Logger to the context.
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor
UnaryClientInterceptor returns a new unary client interceptor that optionally logs the execution of external gRPC calls.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptors that adds zap.Logger 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 MessageProducer ¶
type MessageProducer func(ctx context.Context, msg string, level logger.Level, code codes.Code, err error, duration ctxlog.Fields)
MessageProducer produces a user defined log message
type Option ¶
type Option func(*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.
func WithMessageProducer ¶
func WithMessageProducer(f MessageProducer) Option
WithMessageProducer customizes the function for message formation.
func WithTimestampFormat ¶
WithTimestampFormat customizes the timestamps emitted in the log fields.