Documentation ¶
Overview ¶
Package cloudrequestlog contains primitives for request logging.
Index ¶
- func CodeToLevel(code codes.Code) slog.Level
- func ErrorDetails(err error) zap.Field
- func WithAdditionalFields(ctx context.Context) context.Context
- type AdditionalFields
- type Config
- type Middleware
- func (l *Middleware) GRPCStreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func (l *Middleware) GRPCUnaryClientInterceptor(ctx context.Context, fullMethod string, request interface{}, ...) error
- func (l *Middleware) GRPCUnaryServerInterceptor(ctx context.Context, request interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func (l *Middleware) HTTPServer(next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CodeToLevel ¶ added in v0.33.0
CodeToLevel returns the default slog.Level for requests with the provided codes.Code.
func ErrorDetails ¶
ErrorDetails creates a zap.Field that logs the gRPC error details of the provided error.
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) AddToArray ¶
func (m *AdditionalFields) AddToArray(key string, objects ...any)
AddToArray adds additional objects to an array field.
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.