slogcommon

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: MIT Imports: 8 Imported by: 59

README

slog toolchain

tag Go Version GoDoc Build Status Go report Coverage Contributors License

A toolchain for slog Go library.

See also:

🚀 Install

go get github.com/samber/slog-common

Compatibility: go >= 1.21

No breaking changes will be made to exported APIs before v2.0.0.

💡 Usage

GoDoc: https://pkg.go.dev/github.com/samber/slog-common

m := AttrsToValue(slog.Bool("foo", true), slog.String("bar", "baz"))
// {"foo": true, "bar": "baz"}

k, v := AttrToValue(slog.Bool("foo", true))
// "foo", true

v := AnyValueToString(slog.IntValue(42))
// "42"

err := fmt.Errorf("an error")

m := FormatErrorKey(map[string]any{"foo": "bar", "msg": err}, "msg")
// {"foo": "bar", "msg": {"kind": "*errorString", "error": "an error", "stack": nil}}

m := FormatError(err)
// {"kind": "*errorString", "error": "an error", "stack": nil}

🤝 Contributing

Don't hesitate ;)

# Install some dev dependencies
make tools

# Run tests
make test
# or
make watch-test

👤 Contributors

Contributors

💫 Show your support

Give a ⭐️ if this project helped you!

GitHub Sponsors

📝 License

Copyright © 2023 Samuel Berthe.

This project is MIT licensed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyValueToString

func AnyValueToString(v slog.Value) string

func AppendAttrsToGroup

func AppendAttrsToGroup(groups []string, actualAttrs []slog.Attr, newAttrs ...slog.Attr) []slog.Attr

func AttrToValue

func AttrToValue(attr slog.Attr) (string, any)

func AttrsToString added in v0.3.0

func AttrsToString(attrs ...slog.Attr) map[string]string

func AttrsToValue

func AttrsToValue(attrs ...slog.Attr) map[string]any

func FindAttrByGroupAndKey

func FindAttrByGroupAndKey(attrs []slog.Attr, groups []string, key string) (slog.Attr, bool)

func FindAttrByKey

func FindAttrByKey(attrs []slog.Attr, key string) (slog.Attr, bool)

func FormatError

func FormatError(err error) map[string]any

func FormatErrorKey

func FormatErrorKey(values map[string]any, errorKey string) map[string]any

func FormatRequest added in v0.5.0

func FormatRequest(req *http.Request, ignoreHeaders bool) map[string]any

func UniqAttrs

func UniqAttrs(attrs []slog.Attr) []slog.Attr

@TODO: should be recursive

func ValueToString added in v0.2.0

func ValueToString(v slog.Value) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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