Documentation
¶
Index ¶
- func LoggerStreamInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func LoggerUnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func NewLoggerInterceptors(z *data.ZapLog, opts ...Option) (grpc.UnaryServerInterceptor, grpc.StreamServerInterceptor)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoggerStreamInterceptor ¶
func LoggerStreamInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
LoggerStreamInterceptor is the legacy stream interceptor preserved for backward compatibility. See LoggerUnaryInterceptor for the rationale — new code should prefer NewLoggerInterceptors.
func LoggerUnaryInterceptor ¶
func LoggerUnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
LoggerUnaryInterceptor is the legacy unary interceptor preserved for backward compatibility. It logs method + duration + status to the standard library log package without structured fields and without any metadata extraction. New code should prefer NewLoggerInterceptors.
This function never panics, never blocks, and never mutates the request/response. It is safe to wire into an interceptor chain regardless of context.
func NewLoggerInterceptors ¶ added in v1.8.0
func NewLoggerInterceptors(z *data.ZapLog, opts ...Option) (grpc.UnaryServerInterceptor, grpc.StreamServerInterceptor)
NewLoggerInterceptors returns a paired (unary, stream) gRPC server interceptor that logs each RPC's method, peer, status code, and duration to the supplied *data.ZapLog. Errors are logged at Errorw; successes at Infow.
If z is nil, both interceptors degrade to no-ops (the request is still served — only logging is skipped). This matches the semantics of data.ZapLog.DisableLogger so that consumers can disable logging by passing a nil logger without changing their interceptor wiring.
PII discipline: error messages are truncated to maxErrorLen bytes; metadata is only logged when WithLogMetadata(true) is set, and even then sensitive headers are redacted (value replaced with "[REDACTED]").
This API is additive — the legacy LoggerUnaryInterceptor and LoggerStreamInterceptor functions remain available as package-level symbols for backward compatibility. New integrations should use this constructor.
Types ¶
type Option ¶ added in v1.8.0
type Option func(*loggerOptions)
Option configures the structured logger interceptors returned by NewLoggerInterceptors. Options follow the standard functional-options idiom — pass any number; later options override earlier ones.
func WithLogMetadata ¶ added in v1.8.0
WithLogMetadata controls whether incoming gRPC metadata is included as a structured field on each log entry. Defaults to false because metadata is a common PII source. When enabled, sensitive headers are still redacted via the denylist.
func WithLogPeer ¶ added in v1.8.0
WithLogPeer controls whether the peer address (from grpc/peer) is included on each log entry. Defaults to true; set false in environments where client IPs are considered PII (e.g. EU consumer endpoints under GDPR).
func WithSensitiveHeaders ¶ added in v1.8.0
WithSensitiveHeaders extends the metadata redaction denylist beyond the built-in set (authorization, cookie, x-api-key, ...). Header names are matched case-insensitively. Use this to redact tenant-specific or product-specific secrets that the default list does not know about.