fix!: don't panic, only accept typed log Fields#222
Conversation
johnstcn
left a comment
There was a problem hiding this comment.
I agree with the reasoning for this change. A couple of things:
-
Per Conventional Commits, we should indicate that this is a breaking change either in the commit message or as a footer in the body.
-
Since this is a breaking change, will we be releasing a new major version of slog?
-
Before this change, you at least had the possibility of determining if you were logging un-marshalable values in testing. Since this is no longer the case, it would be nice if we could detect this in
slogtestand fail the test.
Pull Request Test Coverage Report for Build fdae399baec2a8b264caff53ae9b5db3edd2841a-PR-222Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Yes, this will be v2. |
fixes #221
A breaking change like this is unfortunate, but I feel strongly that it is the best path forward. The above issue gives more background, but briefly, with slog as it is without this PR, passing bad arguments to log calls will cause a panic.
With this PR, slog will not panic, and furthermore, we will have build-time checks that log call arguments are correct.
The breaking changes are that log calls of this form:
are no longer supported, and any code that builds an array of log fields needs to be of type
[]slog.Fieldrather than[]any.This results in a relatively small number of code changes in a big repo like coder/coder: https://github.com/coder/coder/compare/spike/slog-dont-panic?expand=1
slog's README.md has this to say in the "Why?" section:
At some point the decision was made to stray from this principle and we ended up in a place with no static type checking where it is easy to pass invalid fields, and we allowed a usage without syntax grouping of key/value pairs. This PR restores us to these principles.