cloudrequestlog

package
v0.32.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package cloudrequestlog contains primitives for request logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorDetails

func ErrorDetails(err error) zap.Field

ErrorDetails creates a zap.Field that logs the gRPC error details of the provided error.

func WithAdditionalFields

func WithAdditionalFields(ctx context.Context) context.Context

WithAdditionalFields initializes metadata for the current request.

Types

type AdditionalFields

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

AdditionalFields for a request log message.

func GetAdditionalFields

func GetAdditionalFields(ctx context.Context) (*AdditionalFields, bool)

GetAdditionalFields returns the current request metadata.

func (*AdditionalFields) Add

func (m *AdditionalFields) Add(fields ...zap.Field)

Add additional fields.

func (*AdditionalFields) AddToArray

func (m *AdditionalFields) AddToArray(key string, objects ...zapcore.ObjectMarshaler)

AddToArray adds additional objects to an array field.

func (*AdditionalFields) AppendTo

func (m *AdditionalFields) AppendTo(fields []zap.Field) []zap.Field

AppendTo appends the additional fields to the input fields.

type Config

type Config struct {
	// MessageSizeLimit is the maximum size, in bytes, of requests and responses to log.
	// Messages large than the limit will be truncated.
	// Default value, 0, means that no messages will be truncated.
	MessageSizeLimit int `onGCE:"1024"`
	// CodeToLevel enables overriding the default gRPC code to level conversion.
	CodeToLevel map[codes.Code]zapcore.Level
	// StatusToLevel enables overriding the default HTTP status code to level conversion.
	StatusToLevel map[int]zapcore.Level
}

Config contains request logging config.

type Middleware

type Middleware struct {
	// Config for the request logger middleware.
	Config Config
	// MessageTransformer is an optional transform applied to proto.Message request and responses.
	MessageTransformer func(proto.Message) proto.Message
}

Middleware for request logging.

func (*Middleware) GRPCUnaryClientInterceptor

func (l *Middleware) GRPCUnaryClientInterceptor(
	ctx context.Context,
	fullMethod string,
	request interface{},
	response interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption,
) error

GRPCUnaryClientInterceptor provides request logging as a grpc.UnaryClientInterceptor.

func (*Middleware) GRPCUnaryServerInterceptor

func (l *Middleware) GRPCUnaryServerInterceptor(
	ctx context.Context,
	request interface{},
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler,
) (interface{}, error)

GRPCUnaryServerInterceptor implements request logging as a grpc.UnaryServerInterceptor.

func (*Middleware) HTTPServer

func (l *Middleware) HTTPServer(next http.Handler) http.Handler

HTTPServer provides request logging for HTTP servers.

Jump to

Keyboard shortcuts

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