slogm

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 11 Imported by: 2

Documentation

Overview

Package slogm contains middlewares for chaining and decoupling process of enriching or reducing logs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSecrets added in v1.0.0

func AddSecrets(ctx context.Context, secret ...string) context.Context

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

func ContextWithRequestID(parent context.Context, reqID string) context.Context

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

func RequestIDFromContext(ctx context.Context) (string, bool)

RequestIDFromContext returns request id from context.

func SecretsFromContext added in v1.0.0

func SecretsFromContext(ctx context.Context) ([]string, bool)

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 Capturer added in v1.3.0

type Capturer interface {
	Push(slog.Record)
	Records() []slog.Record
	Close() error
}

Capturer is an interface for capturing log records.

type ChannelCapturer added in v1.3.0

type ChannelCapturer chan slog.Record

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL