Skip to content

BUG: wasilog - repeated group when using slog group attributes #365

@jamesstocktonj1

Description

@jamesstocktonj1

Description

When using wasilog and slog the group attributes are repeated with each log call. This seems to be an issue with how the wasilog is implementing the slog.Handler as the repeated group can not be seen when using the native Go logger (e.g. var handler = slog.Default().Handler().WithAttrs(attr)).

Proof

Add the following code to a new template Go function (wash new).

var attr = []slog.Attr{
    slog.String("name", "foo"),
    slog.Group("nested", slog.String("bar", "baz")),
}
var handler = wasilog.DefaultOptions().NewHandler().WithAttrs(attr)
var logger = slog.New(handler)

logger.Info("Hello, World 1!")
logger.Info("Hello, World 2!")
logger.Info("Hello, World 3!")

When calling the function you get the following logs:

INFO <...> Hello, World 1! name="foo" nested.bar="baz"
INFO <...> Hello, World 2! name="foo" nested.nested.bar="baz"
INFO <...> Hello, World 3! name="foo" nested.nested.nested.bar="baz"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions