Skip to content

Commit

Permalink
[Ingest Manager] Logging to file disabled on enroll (elastic#24466)
Browse files Browse the repository at this point in the history
[Ingest Manager] Logging to file disabled on enroll (elastic#24466)
  • Loading branch information
michalpristas committed Mar 10, 2021
1 parent bea9a9b commit 3949300
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion libbeat/logp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- Fix windows installer during enroll {pull}[24343]24343
- Fix failing installation on windows 7 {pull}[24387]24387
- Fix capabilities resolution in inspect command {pull}[24346]24346
- Logging to file disabled on enroll {issue}[24173]24173

==== New features

Expand Down
5 changes: 5 additions & 0 deletions x-pack/elastic-agent/pkg/agent/cmd/enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions x-pack/elastic-agent/pkg/core/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 3949300

Please sign in to comment.