From 19a60f00a11a4a951a300db44981d7c73cc18c78 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 10 Mar 2021 08:59:29 +0100 Subject: [PATCH 1/3] fix/enroll-log-race --- x-pack/elastic-agent/pkg/agent/cmd/enroll.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/x-pack/elastic-agent/pkg/agent/cmd/enroll.go b/x-pack/elastic-agent/pkg/agent/cmd/enroll.go index 2a000684e2d..15c362e9529 100644 --- a/x-pack/elastic-agent/pkg/agent/cmd/enroll.go +++ b/x-pack/elastic-agent/pkg/agent/cmd/enroll.go @@ -187,6 +187,11 @@ func enroll(streams *cli.IOStreams, cmd *cobra.Command, flags *globalFlags, args } } + // enroll is invoked either manually or from install with redirected IO + // no need to log to file + cfg.Settings.LoggingConfig.ToFiles = false + cfg.Settings.LoggingConfig.ToStderr = true + logger, err := logger.NewFromConfig("", cfg.Settings.LoggingConfig) if err != nil { return err From db1a3dc037d784abf657c1277c9ff92022b91bb6 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 10 Mar 2021 10:33:25 +0100 Subject: [PATCH 2/3] to files check --- libbeat/logp/config.go | 3 ++- x-pack/elastic-agent/pkg/core/logger/logger.go | 17 +++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libbeat/logp/config.go b/libbeat/logp/config.go index 3c2f2cde381..be384fe48ac 100644 --- a/libbeat/logp/config.go +++ b/libbeat/logp/config.go @@ -62,7 +62,8 @@ const defaultLevel = InfoLevel // Beat is supposed to be run within. func DefaultConfig(environment Environment) Config { return Config{ - Level: defaultLevel, + Level: defaultLevel, + ToFiles: true, Files: FileConfig{ MaxSize: 10 * 1024 * 1024, MaxBackups: 7, diff --git a/x-pack/elastic-agent/pkg/core/logger/logger.go b/x-pack/elastic-agent/pkg/core/logger/logger.go index 3e70cd88e57..583d91ac48c 100644 --- a/x-pack/elastic-agent/pkg/core/logger/logger.go +++ b/x-pack/elastic-agent/pkg/core/logger/logger.go @@ -54,13 +54,18 @@ func new(name string, cfg *Config) (*Logger, error) { if err != nil { return nil, err } - internal, err := makeInternalFileOutput(cfg) - if err != nil { - return nil, err - } - if err := configure.LoggingWithOutputs("", commonCfg, internal); err != nil { - return nil, fmt.Errorf("error initializing logging: %v", err) + + if cfg.ToFiles { + internal, err := makeInternalFileOutput(cfg) + if err != nil { + return nil, err + } + + if err := configure.LoggingWithOutputs("", commonCfg, internal); err != nil { + return nil, fmt.Errorf("error initializing logging: %v", err) + } } + return logp.NewLogger(name), nil } From 9edef27786174a6948b22eacef61e4884628ec29 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 10 Mar 2021 11:14:35 +0100 Subject: [PATCH 3/3] changelog --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index 12461df3581..5c6cd892008 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -41,6 +41,7 @@ - Fix failing installation on windows 7 {pull}[24387]24387 - Fix capabilities resolution in inspect command {pull}[24346]24346 - Fix windows installer during enroll {pull}[24343]24343 +- Logging to file disabled on enroll {issue}[24173]24173 ==== New features