From 074245d0e2927d7bb224f3df31ddbddea4f5d628 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Tue, 12 Oct 2021 14:38:44 -0400 Subject: [PATCH] wrap `log` messages with `hclog` (#11291) --- .changelog/11291.txt | 3 +++ command/agent/command.go | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changelog/11291.txt diff --git a/.changelog/11291.txt b/.changelog/11291.txt new file mode 100644 index 000000000000..59cef59851e2 --- /dev/null +++ b/.changelog/11291.txt @@ -0,0 +1,3 @@ +```release-note:bug +agent: Fixed an issue that caused some non-JSON log output when `log_json` was enabled +``` diff --git a/command/agent/command.go b/command/agent/command.go index 0346a726c14f..89102f84e46f 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -470,7 +470,6 @@ func SetupLoggers(ui cli.Ui, config *Config) (*logutils.LevelFilter, *gatedwrite } logOutput := io.MultiWriter(writers...) - log.SetOutput(logOutput) return logFilter, logGate, logOutput } @@ -649,6 +648,12 @@ func (c *Command) Run(args []string) int { JSONFormat: config.LogJson, }) + // Wrap log messages emitted with the 'log' package. + // These usually come from external dependencies. + log.SetOutput(logger.StandardWriter(&hclog.StandardLoggerOptions{InferLevels: true})) + log.SetPrefix("") + log.SetFlags(0) + // Swap out UI implementation if json logging is enabled if config.LogJson { c.Ui = &logging.HcLogUI{Log: logger}