Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion logp/logptest/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ type Logger struct {
// replacement for a *logp.Logger, or the logger can be accessed via
// [Logger.Logger]
func NewFileLogger(t testing.TB, dir string) *Logger {
encoderConfig := ecszap.ECSCompatibleEncoderConfig(zapcore.EncoderConfig{})
encoderConfig := ecszap.ECSCompatibleEncoderConfig(zapcore.EncoderConfig{
// As long as NameKey is NOT EMPTY it will be overridden
// by the correct key. So we set it to 'enabled' to make it very
// clear this is NOT the final key for the logger name.
NameKey: "enabled",
})
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
encoder := zapcore.NewJSONEncoder(encoderConfig)

Expand Down
6 changes: 6 additions & 0 deletions logp/logptest/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

func TestNewFileLogger(t *testing.T) {
logger := NewFileLogger(t, "")
logger.Logger = logger.Named("test-logger")
logger.Debug("foo")

assertLogFormat(t, logger.logFile.Name())
Expand Down Expand Up @@ -93,6 +94,7 @@ func assertLogFormat(t *testing.T, path string) {
entry := struct {
Timestamp string `json:"@timestamp"`
LogLevel string `json:"log.level"`
Logger string `json:"log.logger"`
Message string `json:"message"`
}{}

Expand All @@ -112,6 +114,10 @@ func assertLogFormat(t *testing.T, path string) {
if entry.Message == "" {
t.Error("message cannot be empty")
}

if entry.Logger == "" {
t.Error("'log.logger' cannot be empty")
}
}
}

Expand Down
Loading