logging

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2023 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package logging implements grpc logging middleware.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCodeToLevel

func DefaultCodeToLevel(code codes.Code) logging.Level

DefaultCodeToLevel the default grpc status code to log level

func FullMethod added in v0.2.21

func FullMethod(service, method string) string

func StreamClientInterceptor

func StreamClientInterceptor(logger logging.Logger, opts ...Option) grpc.StreamClientInterceptor

StreamClientInterceptor returns a new streaming client interceptor that optionally logs the execution of external gRPC calls. Logger will use all tags (from tags package) available in current context as fields.

func StreamServerInterceptor

func StreamServerInterceptor(logger logging.Logger, opts ...Option) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new stream server interceptors that optionally logs endpoint handling. Logger will use all tags (from tags package) available in current context as fields.

func UnaryClientInterceptor

func UnaryClientInterceptor(logger logging.Logger, opts ...Option) grpc.UnaryClientInterceptor

UnaryClientInterceptor returns a new unary client interceptor that optionally logs the execution of external gRPC calls. Logger will use all tags (from tags package) available in current context as fields.

func UnaryServerInterceptor

func UnaryServerInterceptor(logger logging.Logger, opts ...Option) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptors that optionally logs endpoint handling. Logger will use all tags (from tags package) available in current context as fields.

Types

type Decider

type Decider func(fullMethod string, err error) PayloadDecision

Decider function defines rules for suppressing any interceptor logs

type Option

type Option func(*options)

Option the Options for this module

func WithDecider

func WithDecider(f Decider) Option

WithDecider customizes the function for deciding if the gRPC interceptor logs should log.

func WithLevels

func WithLevels(f logging.CodeToLevel) Option

WithLevels customizes the function for mapping gRPC return codes and interceptor log level statements.

func WithRequestFieldExtractorFunc

func WithRequestFieldExtractorFunc(f RequestFieldExtractorFunc) Option

WithRequestFieldExtractorFunc customizes the function for extracting log fields from protobuf messages, for unary and server-streamed methods only.

func WithResponseFieldExtractorFunc

func WithResponseFieldExtractorFunc(f ResponseFieldExtractorFunc) Option

WithResponseFieldExtractorFunc customizes the function for extracting log fields from protobuf messages, for unary and server-streamed methods only.

type PayloadDecision

type PayloadDecision struct {
	Enable     logging.Decision
	Request    bool
	Response   bool
	ClearBytes bool
}

PayloadDecision defines rules for enabling Request or Response logging

func DefaultLoggingDeciderMethod

func DefaultLoggingDeciderMethod(_ string, _ error) PayloadDecision

DefaultLoggingDeciderMethod is the default implementation of decider to see if you should log the call by default this if always true so all calls are logged

type RequestFieldExtractorFunc

type RequestFieldExtractorFunc func(fullMethod string, req interface{}) map[string]string

RequestFieldExtractorFunc is a user-provided function that extracts field information from a gRPC request. It is called from tags middleware on arrival of unary request or a server-stream request. Keys and values will be added to the context tags of the request. If there are no fields, you should return a nil.

type ResponseFieldExtractorFunc

type ResponseFieldExtractorFunc func(fullMethod string, resp interface{}) map[string]string

ResponseFieldExtractorFunc is a user-provided function that extracts field information from a gRPC response. It is called from tags middleware on arrival of unary request or a server-stream request. Keys and values will be added to the context tags of the request. If there are no fields, you should return a nil.

Jump to

Keyboard shortcuts

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