Documentation ΒΆ
Index ΒΆ
- func FlattenAttrs(attrs []slog.Attr) []slog.Attr
- func FlattenAttrsWithPrefix(separator string, prefix string, attrs []slog.Attr) []slog.Attr
- func NewFormatterHandler(formatters ...Formatter) func(slog.Handler) slog.Handler
- func NewFormatterMiddleware(formatters ...Formatter) slogmulti.Middleware
- func PrefixAttrKeys(prefix string, attrs []slog.Attr) []slog.Attr
- type FlattenFormatterMiddleware
- func (h *FlattenFormatterMiddleware) Enabled(ctx context.Context, level slog.Level) bool
- func (h *FlattenFormatterMiddleware) Handle(ctx context.Context, record slog.Record) error
- func (h *FlattenFormatterMiddleware) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *FlattenFormatterMiddleware) WithGroup(name string) slog.Handler
- type FlattenFormatterMiddlewareOptions
- type Formatter
- func ErrorFormatter(fieldName string) Formatter
- func Format[T any](formatter func([]string, string, slog.Value) slog.Value) Formatter
- func FormatByFieldType[T any](key string, formatter func(T) slog.Value) Formatter
- func FormatByGroup(groups []string, formatter func([]slog.Attr) slog.Value) Formatter
- func FormatByGroupKey(groups []string, key string, formatter func(slog.Value) slog.Value) Formatter
- func FormatByGroupKeyType[T any](groups []string, key string, formatter func(T) slog.Value) Formatter
- func FormatByKey(key string, formatter func(slog.Value) slog.Value) Formatter
- func FormatByKind(kind slog.Kind, formatter func(slog.Value) slog.Value) Formatter
- func FormatByType[T any](formatter func(T) slog.Value) Formatter
- func HTTPRequestFormatter(ignoreHeaders bool) Formatter
- func HTTPResponseFormatter(ignoreHeaders bool) Formatter
- func IPAddressFormatter(key string) Formatter
- func PIIFormatter(key string) Formatter
- func TimeFormatter(timeFormat string, location *time.Location) Formatter
- func TimezoneConverter(location *time.Location) Formatter
- func UnixTimestampFormatter(precision time.Duration) Formatter
- type FormatterHandler
- type LogValuerFunc
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func FlattenAttrs ΒΆ added in v0.5.0
FlattenAttrs flatten attributes recursively.
func FlattenAttrsWithPrefix ΒΆ added in v0.5.0
FlattenAttrsWithPrefix flatten attributes recursively, with prefix.
func NewFormatterHandler ΒΆ
NewFormatterHandler returns a slog.Handler that applies formatters to.
func NewFormatterMiddleware ΒΆ
func NewFormatterMiddleware(formatters ...Formatter) slogmulti.Middleware
NewFormatterMiddleware returns slog-multi middleware.
Types ΒΆ
type FlattenFormatterMiddleware ΒΆ added in v0.5.0
type FlattenFormatterMiddleware struct {
// contains filtered or unexported fields
}
type FlattenFormatterMiddlewareOptions ΒΆ added in v0.5.0
type FlattenFormatterMiddlewareOptions struct { // Ignore attribute path and therefore ignore attribute key prefix. // Some attribute keys may collide. IgnorePath bool // Separator between prefix and key. Separator string // Attribute key prefix. Prefix string }
func (FlattenFormatterMiddlewareOptions) NewFlattenFormatterMiddlewareOptions ΒΆ added in v0.5.0
func (o FlattenFormatterMiddlewareOptions) NewFlattenFormatterMiddlewareOptions() slogmulti.Middleware
NewFlattenFormatterMiddlewareOptions returns a formatter middleware that flatten attributes recursively.
type Formatter ΒΆ
func ErrorFormatter ΒΆ
ErrorFormatter transforms a go error into a readable error.
Example:
err := reader.Close() err = fmt.Errorf("could not close reader: %v", err) logger.With("error", reader.Close()).Log("error")
passed to ErrorFormatter("error"), will be transformed into:
"error": { "message": "could not close reader: file already closed", "type": "*io.ErrClosedPipe" }
func FormatByFieldType ΒΆ
FormatByFieldType pass attributes matching both key and generic type into a formatter.
func FormatByGroup ΒΆ
FormatByGroup pass attributes under a group into a formatter.
func FormatByGroupKey ΒΆ
FormatByGroupKey pass attributes under a group and matching key, into a formatter.
func FormatByGroupKeyType ΒΆ
func FormatByGroupKeyType[T any](groups []string, key string, formatter func(T) slog.Value) Formatter
FormatByGroupKeyType pass attributes under a group, matching key and matching a generic type, into a formatter.
func FormatByKey ΒΆ
FormatByKey pass attributes matching key into a formatter.
func FormatByKind ΒΆ added in v0.3.0
FormatByKind pass attributes matching `slog.Kind` into a formatter.
func FormatByType ΒΆ
FormatByType pass attributes matching generic type into a formatter.
func HTTPRequestFormatter ΒΆ added in v0.2.0
HTTPRequestFormatter transforms a *http.Request into a readable object.
func HTTPResponseFormatter ΒΆ added in v0.2.0
HTTPResponseFormatter transforms a *http.Response into a readable object.
func IPAddressFormatter ΒΆ
IPAddressFormatter transforms an IP address into "********".
Example:
"context": { "ip_address": "bd57ffbd-8858-4cc4-a93b-426cef16de61" }
passed to IPAddressFormatter("ip_address"), will be transformed into:
"context": { "ip_address": "********", }
func PIIFormatter ΒΆ
PIIFormatter transforms any value under provided key into "********". IDs are kept as is.
Example:
"user": { "id": "bd57ffbd-8858-4cc4-a93b-426cef16de61", "email": "foobar@example.com", "address": { "street": "1st street", "city": "New York", "country": USA", "zip": 123456 } }
passed to PIIFormatter("user"), will be transformed into:
"user": { "id": "bd57ffbd-8858-4cc4-a93b-426cef16de61", "email": "foob********", "address": { "street": "1st *******", "city": "New *******", "country": "*******", "zip": "*******" } }
func TimeFormatter ΒΆ added in v0.3.0
TimeFormatter transforms a `time.Time` into a readable string.
func TimezoneConverter ΒΆ added in v0.3.0
TimezoneConverter set a `time.Time` to a different timezone.
func UnixTimestampFormatter ΒΆ added in v0.3.0
UnixTimestampFormatter transforms a `time.Time` into a unix timestamp.
type FormatterHandler ΒΆ
type FormatterHandler struct {
// contains filtered or unexported fields
}