Skip to content
Closed
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
18 changes: 7 additions & 11 deletions logp/logptest/logptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,19 @@ import (

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest"
"go.uber.org/zap/zaptest/observer"

"github.com/elastic/elastic-agent-libs/logp"
)

// NewTestingLogger returns a testing suitable logp.Logger that uses the
// [testing.T] as the logger output.
// NewTestingLogger Just calls [NewFileLogger], the log if is placed in the
// the folder returned by [os.TempDir].
//
// DEPRECATED: The logger returned by [NewTestingLogger] can panic if it is
// used after the test has ended. Use [NewFileLogger] instead.
Comment on lines +33 to +34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do this, the testing logger is integrated in the stdlib testing infra.

The panic is exposing a bug in the code, that's where it should be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created elastic/beats#47527 to track the failing tests because of the logger issue.

func NewTestingLogger(t testing.TB, selector string, options ...logp.LogOption) *logp.Logger {
log := zaptest.NewLogger(t, zaptest.WrapOptions(options...))
log = log.Named(selector)

logger, err := logp.NewZapLogger(log)
if err != nil {
t.Fatal(err)
}
return logger
l := NewFileLogger(t, "")
return l.Logger
}

// NewTestingLoggerWithObserver returns a testing suitable logp.Logger that uses the
Expand Down
Loading