-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/log entry set fields #38
base: master
Are you sure you want to change the base?
Bugfix/log entry set fields #38
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is effectively patching the current problem of the misuse of the variadic arguments in With
.
attrs := make([]slog.Attr, len(fields)) | ||
attrs := make([]any, len(fields)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change really necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…g arguments correctly Without the change in this changeset, running `go test` fails with: ``` ./httplog.go:361:37: slog.Logger.With arg "attrs" should be a string or a slog.Attr (possible missing key or value) FAIL ``` This is due to the fact that the array of `slog.Attr`s was supplied as a single arg (i.e. a single slice of attributes) to `*entry.Logger.With`, instead of a variable number of arguments. Example: ```go fields := map[string]any{ "remote": "example.com", "action": "update", } httplog.LogEntrySetFields(ctx, fields) ``` Without this change, the updated example that uses LogEntrySetFields creates the following log entry: ``` user: "user1" !BADKEY: [remote=example.com action=update] ``` With the change the log line for the updated example is: ``` user: "user1" remote: "example.com" action: "update" ```
973b3db
to
dae0025
Compare
Updated the PR to incorporate the latest changes from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'm not the maintainer, just a user ^^'
LogEntrySetFields
: Use the varargs syntax to supply the additional log arguments correctlyWithout the change in this changeset, running
go test
fails with:This is due to the fact that the array of
slog.Attr
s was supplied asa single arg (i.e. a single slice of attributes) to
*entry.Logger.With
, instead of a variable number of arguments.Example:
Without this change, the updated example that uses LogEntrySetFields
creates the following log entry:
With the change the log line for the updated example is: