diff --git a/logger_bench_test.go b/logger_bench_test.go index 431cce529..9d4129826 100644 --- a/logger_bench_test.go +++ b/logger_bench_test.go @@ -220,7 +220,7 @@ func Benchmark5WithLazysNotUsed(b *testing.B) { benchmarkWithUsed(b, (*Logger).WithLazy, 5, false) } -func benchmarkWithUsed(b *testing.B, withMethodExpr func(*Logger, ...zapcore.Field) *Logger, N int, use bool) { +func benchmarkWithUsed(b *testing.B, withMethod func(*Logger, ...zapcore.Field) *Logger, N int, use bool) { keys := make([]string, N) values := make([]string, N) for i := 0; i < N; i++ { @@ -232,7 +232,7 @@ func benchmarkWithUsed(b *testing.B, withMethodExpr func(*Logger, ...zapcore.Fie withBenchedLogger(b, func(log *Logger) { for i := 0; i < N; i++ { - log = withMethodExpr(log, String(keys[i], values[i])) + log = withMethod(log, String(keys[i], values[i])) } if use { log.Info("used") diff --git a/logger_test.go b/logger_test.go index 890280b2f..3128a4051 100644 --- a/logger_test.go +++ b/logger_test.go @@ -124,11 +124,10 @@ func TestLoggerInitialFields(t *testing.T) { } func TestLoggerWith(t *testing.T) { - for _, tt := range []struct { - name string - initialFields []Field - withMethodExpr func(*Logger, ...Field) *Logger + name string + initialFields []Field + withMethod func(*Logger, ...Field) *Logger }{ { "regular non lazy logger", @@ -155,10 +154,10 @@ func TestLoggerWith(t *testing.T) { withLogger(t, DebugLevel, opts(Fields(tt.initialFields...)), func(logger *Logger, logs *observer.ObservedLogs) { // Child loggers should have copy-on-write semantics, so two children // shouldn't stomp on each other's fields or affect the parent's fields. - tt.withMethodExpr(logger).Info("") - tt.withMethodExpr(logger, String("one", "two")).Info("") - tt.withMethodExpr(logger, String("three", "four")).Info("") - tt.withMethodExpr(logger, String("five", "six")).With(String("seven", "eight")).Info("") + tt.withMethod(logger).Info("") + tt.withMethod(logger, String("one", "two")).Info("") + tt.withMethod(logger, String("three", "four")).Info("") + tt.withMethod(logger, String("five", "six")).With(String("seven", "eight")).Info("") logger.Info("") assert.Equal(t, []observer.LoggedEntry{ @@ -175,13 +174,13 @@ func TestLoggerWith(t *testing.T) { func TestLoggerWithCaptures(t *testing.T) { for _, tt := range []struct { - name string - withMethodExpr func(*Logger, ...Field) *Logger - wantJSON [2]string + name string + withMethod func(*Logger, ...Field) *Logger + wantJSON [2]string }{ { - name: "regular with captures arguments at time of With", - withMethodExpr: (*Logger).With, + name: "regular with captures arguments at time of With", + withMethod: (*Logger).With, wantJSON: [2]string{ `{ "m": "hello", @@ -196,8 +195,8 @@ func TestLoggerWithCaptures(t *testing.T) { }, }, { - name: "lazy with captures arguments at time of With or Logging", - withMethodExpr: (*Logger).WithLazy, + name: "lazy with captures arguments at time of With or Logging", + withMethod: (*Logger).WithLazy, wantJSON: [2]string{ `{ "m": "hello", @@ -227,11 +226,11 @@ func TestLoggerWithCaptures(t *testing.T) { }) // Demonstrate the arguments are captured when With() and Info() are invoked. - logger = tt.withMethodExpr(logger, Array("a", arr)) + logger = tt.withMethod(logger, Array("a", arr)) x = 1 logger.Info("hello", Array("b", arr)) x = 2 - logger = tt.withMethodExpr(logger, Array("c", arr)) + logger = tt.withMethod(logger, Array("c", arr)) logger.Info("world") if lines := bs.Lines(); assert.Len(t, lines, 2) {