Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap log messages with hclog #11291

Merged
merged 3 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 could cause some non-JSON outputs
```
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