Skip to content

Commit 3f20106

Browse files
authored
lint: Remove redundant embedded field accesses (#1051)
Because the corresponded type is embedded, we can access these fields directly.
1 parent c087e07 commit 3f20106

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

clock_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ func TestWithClock(t *testing.T) {
4242
withLogger(t, DebugLevel, []Option{WithClock(clock)}, func(log *Logger, logs *observer.ObservedLogs) {
4343
log.Info("")
4444
require.Equal(t, 1, logs.Len(), "Expected only one log entry to be written.")
45-
assert.Equal(t, date, logs.All()[0].Entry.Time, "Unexpected entry time.")
45+
assert.Equal(t, date, logs.All()[0].Time, "Unexpected entry time.")
4646
})
4747
}

global_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func TestRedirectStdLogCaller(t *testing.T) {
171171
log.Print("redirected")
172172
entries := logs.All()
173173
require.Len(t, entries, 1, "Unexpected number of logs.")
174-
assert.Contains(t, entries[0].Entry.Caller.File, "global_test.go", "Unexpected caller annotation.")
174+
assert.Contains(t, entries[0].Caller.File, "global_test.go", "Unexpected caller annotation.")
175175
})
176176
}
177177

@@ -210,7 +210,7 @@ func TestRedirectStdLogAtCaller(t *testing.T) {
210210
log.Print("redirected")
211211
entries := logs.All()
212212
require.Len(t, entries, 1, "Unexpected number of logs.")
213-
assert.Contains(t, entries[0].Entry.Caller.File, "global_test.go", "Unexpected caller annotation.")
213+
assert.Contains(t, entries[0].Caller.File, "global_test.go", "Unexpected caller annotation.")
214214
})
215215
}
216216
}
@@ -270,11 +270,11 @@ func checkStdLogMessage(t *testing.T, msg string, logs *observer.ObservedLogs) {
270270
require.Equal(t, 1, logs.Len(), "Expected exactly one entry to be logged")
271271
entry := logs.AllUntimed()[0]
272272
assert.Equal(t, []Field{}, entry.Context, "Unexpected entry context.")
273-
assert.Equal(t, "redirected", entry.Entry.Message, "Unexpected entry message.")
273+
assert.Equal(t, "redirected", entry.Message, "Unexpected entry message.")
274274
assert.Regexp(
275275
t,
276276
`/global_test.go:\d+$`,
277-
entry.Entry.Caller.String(),
277+
entry.Caller.String(),
278278
"Unexpected caller annotation.",
279279
)
280280
}

logger.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,16 @@ func (log *Logger) check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
314314
log.errorOutput.Sync()
315315
}
316316

317-
ce.Entry.Caller = zapcore.EntryCaller{
317+
ce.Caller = zapcore.EntryCaller{
318318
Defined: defined,
319319
PC: frame.PC,
320320
File: frame.File,
321321
Line: frame.Line,
322322
Function: frame.Function,
323323
}
324324
}
325-
if log.addStack.Enabled(ce.Entry.Level) {
326-
ce.Entry.Stack = StackSkip("", log.callerSkip+callerSkipOffset).String
325+
if log.addStack.Enabled(ce.Level) {
326+
ce.Stack = StackSkip("", log.callerSkip+callerSkipOffset).String
327327
}
328328

329329
return ce

logger_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,15 @@ func TestLoggerNames(t *testing.T) {
284284
}
285285
log.Info("")
286286
require.Equal(t, 1, logs.Len(), "Expected only one log entry to be written.")
287-
assert.Equal(t, tt.expected, logs.AllUntimed()[0].Entry.LoggerName, "Unexpected logger name.")
287+
assert.Equal(t, tt.expected, logs.AllUntimed()[0].LoggerName, "Unexpected logger name.")
288288
})
289289
withSugar(t, DebugLevel, nil, func(log *SugaredLogger, logs *observer.ObservedLogs) {
290290
for _, n := range tt.names {
291291
log = log.Named(n)
292292
}
293293
log.Infow("")
294294
require.Equal(t, 1, logs.Len(), "Expected only one log entry to be written.")
295-
assert.Equal(t, tt.expected, logs.AllUntimed()[0].Entry.LoggerName, "Unexpected logger name.")
295+
assert.Equal(t, tt.expected, logs.AllUntimed()[0].LoggerName, "Unexpected logger name.")
296296
})
297297
}
298298
}
@@ -359,7 +359,7 @@ func TestLoggerAddCaller(t *testing.T) {
359359
assert.Regexp(
360360
t,
361361
tt.pat,
362-
output[0].Entry.Caller,
362+
output[0].Caller,
363363
"Expected to find package name and file name in output.",
364364
)
365365
})
@@ -432,14 +432,14 @@ func TestLoggerAddCallerFunction(t *testing.T) {
432432
assert.Regexp(
433433
t,
434434
tt.loggerFunction,
435-
entry.Entry.Caller.Function,
435+
entry.Caller.Function,
436436
"Expected to find function name in output.",
437437
)
438438
}
439439
assert.Regexp(
440440
t,
441441
tt.sugaredFunction,
442-
entries[1].Entry.Caller.Function,
442+
entries[1].Caller.Function,
443443
"Expected to find function name in output.",
444444
)
445445
})
@@ -458,12 +458,12 @@ func TestLoggerAddCallerFail(t *testing.T) {
458458
)
459459
assert.Equal(
460460
t,
461-
logs.AllUntimed()[0].Entry.Message,
461+
logs.AllUntimed()[0].Message,
462462
"Failure.",
463463
"Expected original message to survive failures in runtime.Caller.")
464464
assert.Equal(
465465
t,
466-
logs.AllUntimed()[0].Entry.Caller.Function,
466+
logs.AllUntimed()[0].Caller.Function,
467467
"",
468468
"Expected function name to be empty string.")
469469
})
@@ -489,7 +489,7 @@ func TestLoggerIncreaseLevel(t *testing.T) {
489489
require.Equal(t, 2, logs.Len(), "expected only warn + error logs due to IncreaseLevel.")
490490
assert.Equal(
491491
t,
492-
logs.AllUntimed()[0].Entry.Message,
492+
logs.AllUntimed()[0].Message,
493493
"logger.Warn",
494494
"Expected first logged message to be warn level message",
495495
)

sugar_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func TestSugarAddCaller(t *testing.T) {
344344
assert.Regexp(
345345
t,
346346
tt.pat,
347-
output[0].Entry.Caller,
347+
output[0].Caller,
348348
"Expected to find package name and file name in output.",
349349
)
350350
})
@@ -363,7 +363,7 @@ func TestSugarAddCallerFail(t *testing.T) {
363363
)
364364
assert.Equal(
365365
t,
366-
logs.AllUntimed()[0].Entry.Message,
366+
logs.AllUntimed()[0].Message,
367367
"Failure.",
368368
"Expected original message to survive failures in runtime.Caller.")
369369
})

0 commit comments

Comments
 (0)