Documentation ¶
Overview ¶
Package slogm contains middlewares for chaining and decoupling process of enriching or reducing logs.
Index ¶
- func AddSecrets(ctx context.Context, secret ...string) context.Context
- func Capture(capt Capturer) slogx.Middleware
- func ContextWithRequestID(parent context.Context, reqID string) context.Context
- func MaskSecrets(replacement string) slogx.Middleware
- func RequestID() slogx.Middleware
- func RequestIDFromContext(ctx context.Context) (string, bool)
- func SecretsFromContext(ctx context.Context) ([]string, bool)
- func StacktraceOnError() slogx.Middleware
- func TrimAttrs(limit int) slogx.Middleware
- type Capturer
- type ChannelCapturer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSecrets ¶ added in v1.0.0
AddSecrets adds secrets to the context secrets container.
func Capture ¶ added in v1.3.0
func Capture(capt Capturer) slogx.Middleware
Capture returns a middleware that captures log records.
func ContextWithRequestID ¶
ContextWithRequestID returns a new context with the given request ID.
func MaskSecrets ¶ added in v1.0.0
func MaskSecrets(replacement string) slogx.Middleware
MaskSecrets is a middleware that masks secrets (retrieved from context) in logs.
Works only with attributes of type String/[]byte or Any. If attribute is of type Any, there will be attempt to match it to: - encoding.TextMarshaler - json.Marshaler - []byte if it didn't match to any of these, it will be formatted with %+v and then masked.
Child calls can add secrets to the container only if it's already present in the context, so before any call, user should initialize it with the first "AddSecrets" call, e.g.:
ctx = AddSecrets(ctx)
func RequestID ¶
func RequestID() slogx.Middleware
RequestID returns a middleware that adds request id to record.
func RequestIDFromContext ¶
RequestIDFromContext returns request id from context.
func SecretsFromContext ¶ added in v1.0.0
SecretsFromContext returns secrets from context.
func StacktraceOnError ¶
func StacktraceOnError() slogx.Middleware
StacktraceOnError returns a middleware that adds stacktrace to record if level is error.
func TrimAttrs ¶
func TrimAttrs(limit int) slogx.Middleware
TrimAttrs returns a middleware that trims attributes to the provided limit. Works only with attributes of type String/[]byte or Any.
Types ¶
type ChannelCapturer ¶ added in v1.3.0
ChannelCapturer is a channel that captures log records.
func (ChannelCapturer) Close ¶ added in v1.3.0
func (c ChannelCapturer) Close() error
Close closes the channel.
func (ChannelCapturer) Push ¶ added in v1.3.0
func (c ChannelCapturer) Push(rec slog.Record)
Push adds a record to the channel.
func (ChannelCapturer) Records ¶ added in v1.3.0
func (c ChannelCapturer) Records() []slog.Record
Records returns all captured records for this moment.