cloudrequestlog

package
v0.80.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 24 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 CodeToLevel added in v0.33.0

func CodeToLevel(code codes.Code) slog.Level

CodeToLevel returns the default slog.Level for requests with the provided codes.Code.

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(args ...any)

Add additional fields.

func (*AdditionalFields) AddToArray

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

AddToArray adds additional objects to an array field.

func (*AdditionalFields) AppendTo

func (m *AdditionalFields) AppendTo(attrs []slog.Attr) []slog.Attr

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]slog.Level
	// StatusToLevel enables overriding the default HTTP status code to level conversion.
	StatusToLevel map[int]slog.Level
}

Config contains request logging config.

type Middleware

type Middleware struct {
	// Config for the request logger middleware.
	Config Config
}

Middleware for request logging.

func (*Middleware) GRPCStreamServerInterceptor added in v0.41.0

func (l *Middleware) GRPCStreamServerInterceptor(
	srv interface{},
	ss grpc.ServerStream,
	info *grpc.StreamServerInfo,
	handler grpc.StreamHandler,
) error

GRPCStreamServerInterceptor implements request logging as a grpc.UnaryServerInterceptor. This middleware differs from the unary one in that it does not log request or response payload. The reason for this is that this info is not readily available in the middleware layer.

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