Skip to content

Commit

Permalink
wrap log messages with hclog (#11291)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed Oct 12, 2021
1 parent 721f388 commit 713094f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/11291.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
agent: Fixed an issue that caused some non-JSON log output when `log_json` was enabled
```
7 changes: 6 additions & 1 deletion command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 713094f

Please sign in to comment.