From 3f63c14179e57961b24890e4f5f59d8f0b87470a Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Mon, 29 Jul 2019 21:47:49 -0700 Subject: [PATCH] Setup default logging before logging. --- cmd/telegraf/telegraf.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 2da192da0..6eceb5cdc 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -136,19 +136,10 @@ func loadExternalPlugins(rootDir string) error { return nil } - // name will be the path to the plugin file beginning at the root - // directory, minus the extension. - // ie, if the plugin file is ./telegraf-plugins/foo.so, name - // will be "telegraf-plugins/foo" - name := strings.TrimPrefix(strings.TrimPrefix(pth, rootDir), string(os.PathSeparator)) - name = strings.TrimSuffix(name, filepath.Ext(pth)) - // Load plugin. _, err = plugin.Open(pth) if err != nil { - errorMsg := fmt.Sprintf("error loading [%s]: %s", pth, err) - log.Printf(errorMsg) - return errors.New(errorMsg) + return fmt.Errorf("error loading %s: %s", pth, err) } return nil @@ -161,7 +152,6 @@ func runAgent(ctx context.Context, ) error { // Setup default logging. This may need to change after reading the config // file, but we can configure it to use our logger implementation now. - logger.SetupLogging(logger.LogConfig{}) log.Printf("I! Starting Telegraf %s", version) // If no other options are specified, load the config file and run. @@ -323,11 +313,13 @@ func main() { processorFilters = strings.Split(":"+strings.TrimSpace(*fProcessorFilters)+":", ":") } + logger.SetupLogging(logger.LogConfig{}) + // Load external plugins, if requested. if *fPlugins != "" { - log.Printf("Loading external plugins from: %s\n", *fPlugins) + log.Printf("I! Loading external plugins from: %s", *fPlugins) if err := loadExternalPlugins(*fPlugins); err != nil { - log.Fatal(err.Error()) + log.Fatal("E! " + err.Error()) } }