From 9ed0d0fb649a526c73cb9a33641e1ea0f4af216e Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Fri, 8 Oct 2021 18:14:30 -0400 Subject: [PATCH 1/3] wrap `log` messages with `hclog` --- command/agent/command.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/command/agent/command.go b/command/agent/command.go index 1e753cf2723c..315f9bdd1789 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} From aae687e32bb7d65a2e27ad2fee9dfd7f72a1ebf1 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Fri, 8 Oct 2021 18:25:13 -0400 Subject: [PATCH 2/3] changelog: add entry for #11291 --- .changelog/11291.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/11291.txt diff --git a/.changelog/11291.txt b/.changelog/11291.txt new file mode 100644 index 000000000000..d7f55f94bed2 --- /dev/null +++ b/.changelog/11291.txt @@ -0,0 +1,3 @@ +```release-note:bug +agent: Fixed an issue that could cause some non-JSON outputs +``` From be8a56bf258dc5b6928dcb824fbfefd5a70d4b58 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Tue, 12 Oct 2021 13:56:15 -0400 Subject: [PATCH 3/3] changelog: make #11291 more descriptive --- .changelog/11291.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/11291.txt b/.changelog/11291.txt index d7f55f94bed2..59cef59851e2 100644 --- a/.changelog/11291.txt +++ b/.changelog/11291.txt @@ -1,3 +1,3 @@ ```release-note:bug -agent: Fixed an issue that could cause some non-JSON outputs +agent: Fixed an issue that caused some non-JSON log output when `log_json` was enabled ```