From 76f0e93801e6a8fce0f43496dbdc22701401a143 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 10 Mar 2021 15:32:21 +0100 Subject: [PATCH] [Ingest Manager] Logging to file disabled on enroll (#24466) [Ingest Manager] Logging to file disabled on enroll (#24466) --- libbeat/logp/config.go | 3 ++- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + x-pack/elastic-agent/pkg/agent/cmd/enroll.go | 5 +++++ x-pack/elastic-agent/pkg/core/logger/logger.go | 17 +++++++++++------ 4 files changed, 19 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/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index 1192e3ed91c..c4f7fa88dad 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -40,6 +40,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 diff --git a/x-pack/elastic-agent/pkg/agent/cmd/enroll.go b/x-pack/elastic-agent/pkg/agent/cmd/enroll.go index cd4b12ef422..78fc41f819a 100644 --- a/x-pack/elastic-agent/pkg/agent/cmd/enroll.go +++ b/x-pack/elastic-agent/pkg/agent/cmd/enroll.go @@ -157,6 +157,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 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 }