Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion internal/beatcmd/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ type BeatParams struct {
// ElasticLicensed indicates whether this build of APM Server
// is licensed with the Elastic License v2.
ElasticLicensed bool

// Logger holds the logger used by the runner
Logger *logp.Logger
}

// NewBeat creates a new Beat.
Expand Down Expand Up @@ -144,6 +147,7 @@ func NewBeat(args BeatParams) (*Beat, error) {
Hostname: hostname,
StartTime: time.Now(),
EphemeralID: ephemeralID,
Logger: args.Logger,
},
Keystore: keystore,
Config: &beat.BeatConfig{Output: cfg.Output},
Expand All @@ -170,7 +174,9 @@ func (b *Beat) init() error {
if err := configureLogging(b.Config); err != nil {
return fmt.Errorf("failed to configure logging: %w", err)
}
b.Beat.Info.Logger = logp.NewLogger("")
if b.Info.Logger == nil {
b.Info.Logger = logp.NewLogger("")
}

// log paths values to help with troubleshooting
b.Info.Logger.Infof("%s", paths.Paths.String())
Expand Down
1 change: 1 addition & 0 deletions internal/beatcmd/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ func newBeat(t testing.TB, configYAML string, newRunner NewRunnerFunc) *Beat {
beat, err := NewBeat(BeatParams{
NewRunner: newRunner,
ElasticLicensed: true,
Logger: logptest.NewTestingLogger(t, ""),
})
require.NoError(t, err)
return beat
Expand Down
12 changes: 0 additions & 12 deletions internal/beatcmd/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ import (
"github.com/elastic/elastic-agent-libs/logp"
)

func init() {
// Configure tests to log at debug level, and to send
// logs to logp.ObserverLogs(). It is important to not
// log to files by default in tests, as logp will keep
// the files open and prevent temporary directories from
// being removed on Windows.
logOptions = append(logOptions,
logp.ToObserverOutput(),
logp.WithLevel(logp.DebugLevel),
)
}

var environments = []logp.Environment{
logp.DefaultEnvironment,
logp.SystemdEnvironment,
Expand Down
Loading