From b00ad65b08a97fe657926e87edeaec4f1a509155 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Wed, 12 Oct 2016 15:37:51 +0100 Subject: [PATCH] Log config file parsing errors properly closes #1344 --- CHANGELOG.md | 5 +++++ cmd/telegraf/telegraf.go | 23 +++++++++++------------ internal/config/config.go | 2 +- logger/logger.go | 14 +++++++------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66b18c1fd..a504ac743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Release Notes +- Telegraf now supports two new types of plugins: processors & aggregators. + - On systemd Telegraf will no longer redirect it's stdout to /var/log/telegraf/telegraf.log. On most systems, the logs will be directed to the systemd journal and can be accessed by `journalctl -u telegraf.service`. Consult the systemd journal @@ -11,6 +13,7 @@ continue sending logs to /var/log/telegraf/telegraf.log. ### Features +- [#1726](https://github.com/influxdata/telegraf/issues/1726): Processor & Aggregator plugin support. - [#1861](https://github.com/influxdata/telegraf/pull/1861): adding the tags in the graylog output plugin - [#1732](https://github.com/influxdata/telegraf/pull/1732): Telegraf systemd service, log to journal. - [#1782](https://github.com/influxdata/telegraf/pull/1782): Allow numeric and non-string values for tag_keys. @@ -62,6 +65,8 @@ continue sending logs to /var/log/telegraf/telegraf.log. - [#1836](https://github.com/influxdata/telegraf/pull/1836): Fix snmp table field initialization for non-automatic table. - [#1724](https://github.com/influxdata/telegraf/issues/1724): cgroups path being parsed as metric. - [#1886](https://github.com/influxdata/telegraf/issues/1886): Fix phpfpm fcgi client panic when URL does not exist. +- [#1344](https://github.com/influxdata/telegraf/issues/1344): Fix config file parse error logging. +- [#1771](https://github.com/influxdata/telegraf/issues/1771): Delete nil fields in the metric maker. ## v1.0.1 [2016-09-26] diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index 620479118..347da1985 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -192,7 +192,7 @@ func reloadLoop(stop chan struct{}, s service.Service) { case *fUsage != "": if err := config.PrintInputConfig(*fUsage); err != nil { if err2 := config.PrintOutputConfig(*fUsage); err2 != nil { - log.Fatalf("%s and %s", err, err2) + log.Fatalf("E! %s and %s", err, err2) } } return @@ -204,26 +204,25 @@ func reloadLoop(stop chan struct{}, s service.Service) { c.InputFilters = inputFilters err := c.LoadConfig(*fConfig) if err != nil { - fmt.Println(err) - os.Exit(1) + log.Fatal("E! " + err.Error()) } if *fConfigDirectory != "" { err = c.LoadDirectory(*fConfigDirectory) if err != nil { - log.Fatal(err) + log.Fatal("E! " + err.Error()) } } if len(c.Outputs) == 0 { - log.Fatalf("Error: no outputs found, did you provide a valid config file?") + log.Fatalf("E! Error: no outputs found, did you provide a valid config file?") } if len(c.Inputs) == 0 { - log.Fatalf("Error: no inputs found, did you provide a valid config file?") + log.Fatalf("E! Error: no inputs found, did you provide a valid config file?") } ag, err := agent.NewAgent(c) if err != nil { - log.Fatal(err) + log.Fatal("E! " + err.Error()) } // Setup logging @@ -236,14 +235,14 @@ func reloadLoop(stop chan struct{}, s service.Service) { if *fTest { err = ag.Test() if err != nil { - log.Fatal(err) + log.Fatal("E! " + err.Error()) } return } err = ag.Connect() if err != nil { - log.Fatal(err) + log.Fatal("E! " + err.Error()) } shutdown := make(chan struct{}) @@ -274,7 +273,7 @@ func reloadLoop(stop chan struct{}, s service.Service) { if *fPidfile != "" { f, err := os.Create(*fPidfile) if err != nil { - log.Fatalf("Unable to create pidfile: %s", err) + log.Fatalf("E! Unable to create pidfile: %s", err) } fmt.Fprintf(f, "%d\n", os.Getpid()) @@ -320,7 +319,7 @@ func main() { prg := &program{} s, err := service.New(prg, svcConfig) if err != nil { - log.Fatal(err) + log.Fatal("E! " + err.Error()) } // Handle the -service flag here to prevent any issues with tooling that // may not have an interactive session, e.g. installing from Ansible. @@ -330,7 +329,7 @@ func main() { } err := service.Control(s, *fService) if err != nil { - log.Fatal(err) + log.Fatal("E! " + err.Error()) } } else { err = s.Run() diff --git a/internal/config/config.go b/internal/config/config.go index 0beb4a29c..2c2199dac 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -241,7 +241,7 @@ var header = `# Telegraf Configuration debug = false ## Run telegraf in quiet mode (error log messages only). quiet = false - ## Specify the log file name. The empty string means to log to stdout. + ## Specify the log file name. The empty string means to log to stderr. logfile = "" ## Override default hostname, if empty use os.Hostname() diff --git a/logger/logger.go b/logger/logger.go index fabaabf39..21db2d411 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -27,8 +27,8 @@ func (t *telegrafLog) Write(p []byte) (n int, err error) { // debug will set the log level to DEBUG // quiet will set the log level to ERROR // logfile will direct the logging output to a file. Empty string is -// interpreted as stdout. If there is an error opening the file the -// logger will fallback to stdout. +// interpreted as stderr. If there is an error opening the file the +// logger will fallback to stderr. func SetupLogging(debug, quiet bool, logfile string) { if debug { wlog.SetLevel(wlog.DEBUG) @@ -41,17 +41,17 @@ func SetupLogging(debug, quiet bool, logfile string) { if logfile != "" { if _, err := os.Stat(logfile); os.IsNotExist(err) { if oFile, err = os.Create(logfile); err != nil { - log.Printf("E! Unable to create %s (%s), using stdout", logfile, err) - oFile = os.Stdout + log.Printf("E! Unable to create %s (%s), using stderr", logfile, err) + oFile = os.Stderr } } else { if oFile, err = os.OpenFile(logfile, os.O_APPEND|os.O_WRONLY, os.ModeAppend); err != nil { - log.Printf("E! Unable to append to %s (%s), using stdout", logfile, err) - oFile = os.Stdout + log.Printf("E! Unable to append to %s (%s), using stderr", logfile, err) + oFile = os.Stderr } } } else { - oFile = os.Stdout + oFile = os.Stderr } log.SetOutput(newTelegrafWriter(oFile))