Skip to content

Commit 2aace1a

Browse files
authored
Fix logrus interceptor (#588)
* interceptors: Fix logrus example to iterate over all fields Fixes #570 Signed-off-by: Chance Zibolski <[email protected]> * interceptors: Update zap InterceptorLogger to use Iterator properly The logic in the example is redundant with the logging.Fields Iterator Signed-off-by: Chance Zibolski <[email protected]> --------- Signed-off-by: Chance Zibolski <[email protected]>
1 parent e4c2f09 commit 2aace1a

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

interceptors/logging/examples/logrus/example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func InterceptorLogger(l logrus.FieldLogger) logging.Logger {
1818
return logging.LoggerFunc(func(_ context.Context, lvl logging.Level, msg string, fields ...any) {
1919
f := make(map[string]any, len(fields)/2)
2020
i := logging.Fields(fields).Iterator()
21-
if i.Next() {
21+
for i.Next() {
2222
k, v := i.At()
2323
f[k] = v
2424
}

interceptors/logging/examples/zap/example_test.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ import (
1717
func InterceptorLogger(l *zap.Logger) logging.Logger {
1818
return logging.LoggerFunc(func(ctx context.Context, lvl logging.Level, msg string, fields ...any) {
1919
f := make([]zap.Field, 0, len(fields)/2)
20-
for i := 0; i < len(fields); i += 2 {
21-
i := logging.Fields(fields).Iterator()
22-
if i.Next() {
23-
k, v := i.At()
24-
f = append(f, zap.Any(k, v))
25-
}
20+
i := logging.Fields(fields).Iterator()
21+
for i.Next() {
22+
k, v := i.At()
23+
f = append(f, zap.Any(k, v))
2624
}
2725
l = l.WithOptions(zap.AddCallerSkip(1)).With(f...)
2826

0 commit comments

Comments
 (0)