zerologgrpcprovider

package module
v0.0.0-...-41c4814 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 10 Imported by: 1

README

Zerolog gRPC provider

Simple library for integrating zero log logger into gRPC services. Not customizable, supports only for personal products

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedToCastProtoMessage = errors.New("failed to cast proto message into map")

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger *zerolog.Logger) context.Context

func GetLogger

func GetLogger(ctx context.Context) (*zerolog.Logger, error)

GetLogger returns provided logger from the context

func MustGetLogger

func MustGetLogger(ctx context.Context) *zerolog.Logger

MustGetLogger returns the logger from the context May panic if logger is not available

Types

type Option

type Option func(opts *Options) error

func WithLogErrors

func WithLogErrors(logging bool) Option

When logging errors is true, the logger will print errors after request completion. Default value is true

func WithLogRequests

func WithLogRequests(logging bool) Option

When logging is true, the logger will print messages by self into zerolog output. Default value is true

func WithLogger

func WithLogger(logger *zerolog.Logger) Option

WithLogger changes the default zerolog logger

func WithProvideRequestFieldsToLogger

func WithProvideRequestFieldsToLogger(provideFields bool) Option

When provideFields is enabled, provider will add into zerolog context some request fields Like grpcMethod, grpcServer information etc.

func WithRequestValueModifier

func WithRequestValueModifier(modifier RequestValueModifier) Option

Add request value modifier for modifying request values before they are sent to the output

func WithUseRequestId

func WithUseRequestId(useRequestId bool) Option

When use request id is enabled, interceptor will generate a request identifier in the UUID format and will add this into zerolog context fields list

type Options

type Options struct {
	// contains filtered or unexported fields
}

type RequestValueModifier

type RequestValueModifier func(key string, value any) (newValue any, err error)

Function receiving key and value from the request and returns new value You can use if, for example, for hiding sensitive information from the output Example:

func(key string, value any) (any, error) {
 if key == "password" {
	return "<sensitive_data", nil
 }
 return value, nil
}

type ZerologGrpcProvider

type ZerologGrpcProvider interface {
	// UnaryInterceptor returns interceptor compatible with grpc api for provide zerolog logger
	UnaryInterceptor() grpc.UnaryServerInterceptor
	// StreamInterceptor returns interceptor compatible with grpc api for provide zerolog logger
	StreamInterceptor() grpc.StreamServerInterceptor
	// WithModifiers returns object for customizing zerolog logger
	WithModifiers() *loggerModifiers
}

func New

func New(opts ...Option) (ZerologGrpcProvider, error)

Jump to

Keyboard shortcuts

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