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

logging: Log the cause behind agent startup failure #11353

Merged
merged 3 commits into from
Oct 27, 2021
Merged
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ func (c *Command) setupAgent(config *Config, logger hclog.InterceptLogger, logOu
c.Ui.Output("Starting Nomad agent...")
agent, err := NewAgent(config, logger, logOutput, inmem)
if err != nil {
// log the error as well, so it appears at the end
logger.Error("error starting agent", "error", err)
c.Ui.Error(fmt.Sprintf("Error starting agent: %s", err))
return err
}
Expand Down Expand Up @@ -673,6 +675,14 @@ func (c *Command) Run(args []string) int {
c.Ui = &logging.HcLogUI{Log: logger}
}

// route standard logger to hc-log, so stray log.Printf get tagged with
// timestamps and potentially jsonified
log.SetOutput(logger.StandardWriter(&hclog.StandardLoggerOptions{
InferLevels: true,
}))
log.SetPrefix("")
log.SetFlags(0)

// Log config files
if len(config.Files) > 0 {
c.Ui.Output(fmt.Sprintf("Loaded configuration from %s", strings.Join(config.Files, ", ")))
Expand Down