grpcklog

package
v0.0.0-...-e6d3afb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDurationToField = DurationToTimeMillisField

DefaultDurationToField is the default implementation of converting request duration to a log field (key and value).

Functions

func AddFields

func AddFields(ctx context.Context, fields map[string]interface{})

AddFields adds fields to the logger.

func DurationToDurationField

func DurationToDurationField(duration time.Duration) (key string, value interface{})

DurationToDurationField uses the duration value to log the request duration.

func DurationToTimeMillisField

func DurationToTimeMillisField(duration time.Duration) (key string, value interface{})

DurationToTimeMillisField converts the duration to milliseconds and uses the key `grpc.time_ms`.

func Extract

func Extract(ctx context.Context) map[string]interface{}

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

func ToContext(ctx context.Context, callLog map[string]interface{}) context.Context

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

type CodeToLevel func(code codes.Code) KlogLevel

CodeToLevel function defines the mapping between gRPC return codes and interceptor log level.

type DurationToField

type DurationToField func(duration time.Duration) (key string, value interface{})

DurationToField function defines how to produce duration fields for logging

type KlogLevel

type KlogLevel int

KlogLevel is the Klog Level type

const (
	//InfoLog is info level
	InfoLog KlogLevel = iota
	//WarningLog is warn level
	WarningLog
	//ErrorLog is error level
	ErrorLog
	//FatalLog is fatal level
	FatalLog
)

func DefaultClientCodeToLevel

func DefaultClientCodeToLevel(code codes.Code) KlogLevel

DefaultClientCodeToLevel is the default implementation of gRPC return codes to log levels for client side.

func DefaultCodeToLevel

func DefaultCodeToLevel(code codes.Code) KlogLevel

DefaultCodeToLevel is the default implementation of gRPC return codes to log levels for server side.

func (KlogLevel) String

func (level KlogLevel) String() string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL