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
- func RecoverHandlerError(recovery RecoveryFunc) func(slog.Handler) slog.Handler
- 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(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 HandlerErrorRecovery
- func (h *HandlerErrorRecovery) Enabled(ctx context.Context, l slog.Level) bool
- func (h *HandlerErrorRecovery) Handle(ctx context.Context, record slog.Record) error
- func (h *HandlerErrorRecovery) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *HandlerErrorRecovery) WithGroup(name string) slog.Handler
- type LogValuerFunc
- type RecoveryFunc
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.
func PrefixAttrKeys ¶ added in v0.5.0
PrefixAttrKeys prefix attribute keys.
func RecoverHandlerError ¶ added in v1.2.0
func RecoverHandlerError(recovery RecoveryFunc) func(slog.Handler) slog.Handler
RecoverHandlerError returns a slog.Handler that recovers from panics or error of the chain of handlers.
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 Format ¶
Format returns a Formatter that applies formatter to each attribute, recursively traversing nested groups. The groups slice contains the keys of enclosing groups, from outermost to innermost.
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. This function performs recursive lookup through nested groups to find matching keys.
func FormatByKind ¶ added in v0.3.0
FormatByKind pass attributes matching `slog.Kind` into a formatter. This function performs recursive lookup through nested groups to find matching kinds.
func FormatByType ¶
FormatByType pass attributes matching generic type into a formatter. This function performs recursive lookup through nested groups to find matching types.
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
}
type HandlerErrorRecovery ¶ added in v1.2.0
type HandlerErrorRecovery struct {
// contains filtered or unexported fields
}