Skip to content

Commit b59a888

Browse files
committed
test(beatcmd): use testing logger
1 parent 88446af commit b59a888

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

internal/beatcmd/beat.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ type BeatParams struct {
9797
// ElasticLicensed indicates whether this build of APM Server
9898
// is licensed with the Elastic License v2.
9999
ElasticLicensed bool
100+
101+
// Logger holds the logger used by the runner
102+
Logger *logp.Logger
100103
}
101104

102105
// NewBeat creates a new Beat.
@@ -144,6 +147,7 @@ func NewBeat(args BeatParams) (*Beat, error) {
144147
Hostname: hostname,
145148
StartTime: time.Now(),
146149
EphemeralID: ephemeralID,
150+
Logger: args.Logger,
147151
},
148152
Keystore: keystore,
149153
Config: &beat.BeatConfig{Output: cfg.Output},
@@ -170,7 +174,9 @@ func (b *Beat) init() error {
170174
if err := configureLogging(b.Config); err != nil {
171175
return fmt.Errorf("failed to configure logging: %w", err)
172176
}
173-
b.Beat.Info.Logger = logp.NewLogger("")
177+
if b.Info.Logger == nil {
178+
b.Info.Logger = logp.NewLogger("")
179+
}
174180

175181
// log paths values to help with troubleshooting
176182
b.Info.Logger.Infof("%s", paths.Paths.String())

internal/beatcmd/beat_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ func newBeat(t testing.TB, configYAML string, newRunner NewRunnerFunc) *Beat {
663663
beat, err := NewBeat(BeatParams{
664664
NewRunner: newRunner,
665665
ElasticLicensed: true,
666+
Logger: logptest.NewTestingLogger(t, ""),
666667
})
667668
require.NoError(t, err)
668669
return beat

0 commit comments

Comments
 (0)