refactor: replace zap with slog#2421
Conversation
|
Thanks @danielandersson 👏 I will take a look at this in the coming days 😄 |
internal/log/log.go
Outdated
| if a.Key == slog.LevelKey { | ||
| a.Key = googLvlKey | ||
| return a | ||
| } else if a.Key == slog.MessageKey { |
There was a problem hiding this comment.
We can remove all these else usages, since they immediately follow a return statement.
internal/log/log.go
Outdated
| // replaceAttr remaps default Go logging keys to adhere to LogEntry format | ||
| // https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry | ||
| func replaceAttr(groups []string, a slog.Attr) slog.Attr { | ||
| if groups == nil { |
There was a problem hiding this comment.
Let's invert this check so we don't have to indent the happy path.
https://google.github.io/styleguide/go/decisions#indent-error-flow
internal/log/log.go
Outdated
| ) | ||
|
|
||
| const ( | ||
| googLvlKey = "severity" |
There was a problem hiding this comment.
These are only used in the function below. Let's just inline them.
615ebd8 to
0946cd0
Compare
Thanks for the review, all of your feedback should have been addressed with 0946cd0. |
hessjcg
left a comment
There was a problem hiding this comment.
Thank you for this excellent change! Approved.
|
/gcbrun |
0946cd0 to
b19513a
Compare
|
/gcbrun |
This PR replaces the third-party Zap logging library with Go's standard library
slogpackage for structured logging. This change reduced the number of dependencies while maintaining the same logging functionality and format.Fixes #2120
Changes
go.uber.org/zapandgo.uber.org/zap/zapcorelog/slogpackageStdLoggerstructure by combininginfoLoganddebugLoginto a singlestdLogStructuredLoggerto useslog.Loggerinstead of Zap'sSugaredLoggerNewStructuredLoggerfunction to usesloghandlers and configurationreplaceAttrfunction to maintain compatibility with Google Cloud Logging format