From 8fefb21975ce4ad95db35986925c07dcabf95494 Mon Sep 17 00:00:00 2001 From: Sebastian Spaink <3441183+sspaink@users.noreply.github.com> Date: Mon, 31 Jan 2022 14:30:52 -0600 Subject: [PATCH] fix: move "Starting Telegraf" log (#10528) --- cmd/telegraf/telegraf.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index e14292dc0..4c9ee08ab 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -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.