Documentation
¶
Overview ¶
Package logging defines the logging contracts a service wires into its HTTP and gRPC servers. It holds only interfaces. The presets subpackage implements them for a terminal and for an OpenTelemetry backend.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPConfig ¶ added in v0.21.0
type HTTPConfig interface {
// Logger returns a middleware that wraps a handler and records one
// access-log entry per request, at a level chosen from the response status.
Logger() func(http.Handler) http.Handler
}
HTTPConfig produces the middleware that logs every HTTP request. The presets subpackage implements it for a terminal. Under an OpenTelemetry backend, the server span records each request, and a service installs no HTTPConfig.
type Log ¶ added in v0.20.0
type Log interface {
// Info records a routine event.
Info(ctx context.Context, msg string, fields ...any)
// Warn records a problem the request recovered from.
Warn(ctx context.Context, msg string, fields ...any)
// Err records a failure.
Err(ctx context.Context, msg string, fields ...any)
}
Log is a leveled, context-aware logger. The context carries the request-scoped trace information an implementation attaches to each entry.
Each implementation renders fields to suit its destination. LogOTel hands them to slog, where each becomes a structured attribute a log explorer can filter on. LogLocal formats them into msg as fmt.Sprintf does, and prints one line for a terminal.
Neither drops data. LogLocal appends a field that has no verb to land on, and marks a verb that has no field in place. To log the same line under both, format it into msg and pass no fields.
type RPCConfig ¶ added in v0.21.0
type RPCConfig interface {
// UnaryInterceptor logs each unary call, unless its RPC span is its record.
UnaryInterceptor() grpc.UnaryServerInterceptor
// StreamInterceptor logs each streaming call, unless its RPC span is its record.
StreamInterceptor() grpc.StreamServerInterceptor
// PanicUnaryInterceptor recovers from a panic in a unary handler, logging it
// and returning an internal error to the caller.
PanicUnaryInterceptor() grpc.UnaryServerInterceptor
// PanicStreamInterceptor recovers from a panic in a streaming handler.
PanicStreamInterceptor() grpc.StreamServerInterceptor
}
RPCConfig produces the gRPC server interceptors a service installs. They log each unary and streaming call, and turn a handler panic into an internal error. The presets subpackage implements it for a terminal, and for an OpenTelemetry backend, where the RPC span records each call instead of a log.