Documentation
¶
Overview ¶
Package logging defines the logging contracts a service wires into its HTTP and gRPC servers. It holds only interfaces; the presets subpackage supplies the concrete implementations, in a human-readable local variant and a structured Google Cloud variant.
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 in a local (human-readable) and a Google Cloud (structured) variant.
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.
How fields are rendered belongs to the implementation, and the two presets differ because their destinations do. LogGcloud hands them to slog, where each becomes a structured attribute a log explorer can filter on. LogLocal renders msg as a format string with fields as its operands, which is what reads as a line in a terminal.
A call that passes fields therefore renders differently under each. Neither drops data — a field with no verb to land on is appended, a verb with no field is marked in place — but a caller wanting one exact line should format it into msg and pass no fields. With no fields the two agree.
type RPCConfig ¶ added in v0.21.0
type RPCConfig interface {
// UnaryInterceptor logs each unary call.
UnaryInterceptor() grpc.UnaryServerInterceptor
// StreamInterceptor logs each streaming call.
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: access logging for unary and streaming calls, plus panic recovery that turns a handler panic into an internal error. The presets subpackage implements it in a local and a Google Cloud variant.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package loggingpresets provides ready-made implementations of the logging package interfaces for the two environments a service runs in: Google Cloud and local development.
|
Package loggingpresets provides ready-made implementations of the logging package interfaces for the two environments a service runs in: Google Cloud and local development. |