log

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package log contains interceptor/middleware helpers for logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCodeToLevel

func DefaultCodeToLevel(code codes.Code) std.Level

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

func GetData

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

GetData returns the log field map from the request context.

func New

func New(cfg *Config) interceptor.Middleware

New creates a new Validator interceptor.

Types

type Config

type Config struct {
	// LogStreamRecvMsg if true, log out the contents of each received stream
	// message.
	LogStreamRecvMsg bool
	// LogStreamSendMsg if true, log out the contents of each sent stream
	// message.
	LogStreamSendMsg bool
	// LogUnaryReqMsg if true, log out the contents of the request
	// message/argument/parameters.
	LogUnaryReqMsg bool
	// LogAuthHeader if true, log out the contents of the authorization request
	// header.
	LogAuthHeader bool
	// LogCookies if true, log out the contents of any cookie header.
	LogCookies bool
	// IgnoreHeaders contains a list of request headers to filter from output.
	IgnoreHeaders []string
	// Default fields that should be included with all log messages. These can
	// be overwritten in your application.
	DefaultFields map[string]interface{}
}

Config contains the log interceptor configuration.

type CtxKey

type CtxKey struct{}

CtxKey is the key to use to lookup the log field map in the context.

type Interceptor

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

Interceptor implements gRPC interceptor middleware methods that logs the request as it comes in and the response as it goes out.

func (*Interceptor) StreamInterceptor

func (intr *Interceptor) StreamInterceptor(
	srv interface{},
	stream grpc.ServerStream,
	info *grpc.StreamServerInfo,
	handler grpc.StreamHandler,
) error

StreamInterceptor is a grpc interceptor middleware that logs out the requests as they come in and the responses as they go out.

func (*Interceptor) UnaryInterceptor

func (intr *Interceptor) UnaryInterceptor(
	ctx context.Context,
	req interface{},
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (interface{}, error)

UnaryInterceptor is a grpc interceptor middleware that logs out the request as it comes in, and the response as it goes out.

Jump to

Keyboard shortcuts

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