fix: move "Starting Telegraf" log (#10528)

This commit is contained in:
Sebastian Spaink 2022-01-31 14:30:52 -06:00 committed by GitHub
parent ac65eb6325
commit 8fefb21975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 15 deletions

View File

@ -198,8 +198,6 @@ func runAgent(ctx context.Context,
inputFilters []string,
outputFilters []string,
) error {
log.Printf("I! Starting Telegraf %s", version)
// If no other options are specified, load the config file and run.
c := config.NewConfig()
c.OutputFilters = outputFilters
@ -241,26 +239,22 @@ func runAgent(ctx context.Context,
return fmt.Errorf("Agent flush_interval must be positive; found %v", c.Agent.Interval)
}
ag, err := agent.NewAgent(c)
if err != nil {
return err
}
// Setup logging as configured.
telegraf.Debug = ag.Config.Agent.Debug || *fDebug
telegraf.Debug = c.Agent.Debug || *fDebug
logConfig := logger.LogConfig{
Debug: telegraf.Debug,
Quiet: ag.Config.Agent.Quiet || *fQuiet,
LogTarget: ag.Config.Agent.LogTarget,
Logfile: ag.Config.Agent.Logfile,
RotationInterval: ag.Config.Agent.LogfileRotationInterval,
RotationMaxSize: ag.Config.Agent.LogfileRotationMaxSize,
RotationMaxArchives: ag.Config.Agent.LogfileRotationMaxArchives,
LogWithTimezone: ag.Config.Agent.LogWithTimezone,
Quiet: c.Agent.Quiet || *fQuiet,
LogTarget: c.Agent.LogTarget,
Logfile: c.Agent.Logfile,
RotationInterval: c.Agent.LogfileRotationInterval,
RotationMaxSize: c.Agent.LogfileRotationMaxSize,
RotationMaxArchives: c.Agent.LogfileRotationMaxArchives,
LogWithTimezone: c.Agent.LogWithTimezone,
}
logger.SetupLogging(logConfig)
log.Printf("I! Starting Telegraf %s", version)
log.Printf("I! Loaded inputs: %s", strings.Join(c.InputNames(), " "))
log.Printf("I! Loaded aggregators: %s", strings.Join(c.AggregatorNames(), " "))
log.Printf("I! Loaded processors: %s", strings.Join(c.ProcessorNames(), " "))
@ -284,6 +278,11 @@ func runAgent(ctx context.Context,
log.Printf("W! Deprecated outputs: %d and %d options", count[0], count[1])
}
ag, err := agent.NewAgent(c)
if err != nil {
return err
}
// Notify systemd that telegraf is ready
// SdNotify() only tries to notify if the NOTIFY_SOCKET environment is set, so it's safe to call when systemd isn't present.
// Ignore the return values here because they're not valid for platforms that don't use systemd.