samber / slog-common

Common toolchain for slog
https://pkg.go.dev/github.com/samber/slog-common
MIT License
6 stars 4 forks source link

Question: what is the purpose of this library #1

Closed rvdwijngaard closed 1 year ago

rvdwijngaard commented 1 year ago

Hi @samber,

This library serves the purpose of providing helper functions, such as error formatting, in a consistent manner. However, I'm having trouble understanding how it fits into the slog ecosystem.

In the slog API, the convention is to use the Error function with a message string as the first argument, followed by optional additional arguments for formatting purposes. However, this library uses a map[string]any as its primary data type.

Could you please clarify the purpose of this library and how it relates to the slog ecosystem? I feel like I might be missing something.

samber commented 1 year ago

hi @rvdwijngaard

This library will centralize a few helpers for all my slog libs: much easier to maintain.

This is still WIP (until the end of the week?). I will make the readme more explicit.

Formatters should be added to samber/slog-formatter.

samber commented 1 year ago

The slog stdlib can support many attributes having the same key. But in my handlers, i mostly export attributes to objects.

For faster processing I convert []slog.Attr to map[string]any early. So this is why this lib is doing some stuff on map instead of slog.Attr.

rvdwijngaard commented 1 year ago

Hi @samber thanks for explaining this.