File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,12 @@ type Logger struct {
6060// replacement for a *logp.Logger, or the logger can be accessed via
6161// [Logger.Logger]
6262func NewFileLogger (t testing.TB , dir string ) * Logger {
63- encoderConfig := ecszap .ECSCompatibleEncoderConfig (zapcore.EncoderConfig {})
63+ encoderConfig := ecszap .ECSCompatibleEncoderConfig (zapcore.EncoderConfig {
64+ // As long as NameKey is NOT EMPTY it will be overridden
65+ // by the correct key. So we set it to 'enabled' to make it very
66+ // clear this is NOT the final key for the logger name.
67+ NameKey : "enabled" ,
68+ })
6469 encoderConfig .EncodeTime = zapcore .ISO8601TimeEncoder
6570 encoder := zapcore .NewJSONEncoder (encoderConfig )
6671
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ import (
3333
3434func TestNewFileLogger (t * testing.T ) {
3535 logger := NewFileLogger (t , "" )
36+ logger .Logger = logger .Named ("test-logger" )
3637 logger .Debug ("foo" )
3738
3839 assertLogFormat (t , logger .logFile .Name ())
@@ -93,6 +94,7 @@ func assertLogFormat(t *testing.T, path string) {
9394 entry := struct {
9495 Timestamp string `json:"@timestamp"`
9596 LogLevel string `json:"log.level"`
97+ Logger string `json:"log.logger"`
9698 Message string `json:"message"`
9799 }{}
98100
@@ -112,6 +114,10 @@ func assertLogFormat(t *testing.T, path string) {
112114 if entry .Message == "" {
113115 t .Error ("message cannot be empty" )
114116 }
117+
118+ if entry .Logger == "" {
119+ t .Error ("'log.logger' cannot be empty" )
120+ }
115121 }
116122}
117123
You can’t perform that action at this time.
0 commit comments