Skip to content

Commit

Permalink
nit change loop condition to remove inner check (#5627)
Browse files Browse the repository at this point in the history
  • Loading branch information
wildum authored Oct 27, 2023
1 parent 2a803b0 commit 08b3eee
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions internal/slogadapter/gokit.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,21 @@ func (sa slogAdapter) Enabled(ctx context.Context, l slog.Level) bool {
func (sa slogAdapter) Log(kvps ...interface{}) error {
// Find the log level first, starting with the default.
recordLevel := slog.LevelInfo
for i := 0; i < len(kvps); i += 2 {
for i := 0; i < len(kvps)-1; i += 2 {
if kvps[i] == level.Key() {
if i+1 < len(kvps) {
value := kvps[i+1]
levelValue, _ := value.(level.Value)
switch levelValue {
case level.DebugValue():
recordLevel = slog.LevelDebug
case level.InfoValue():
recordLevel = slog.LevelInfo
case level.WarnValue():
recordLevel = slog.LevelWarn
case level.ErrorValue():
recordLevel = slog.LevelError
}
break
value := kvps[i+1]
levelValue, _ := value.(level.Value)
switch levelValue {
case level.DebugValue():
recordLevel = slog.LevelDebug
case level.InfoValue():
recordLevel = slog.LevelInfo
case level.WarnValue():
recordLevel = slog.LevelWarn
case level.ErrorValue():
recordLevel = slog.LevelError
}
break
}
}

Expand Down

0 comments on commit 08b3eee

Please sign in to comment.