Log config file parsing errors properly

closes #1344
This commit is contained in:
Cameron Sparr
2016-10-12 15:37:51 +01:00
parent a84ce5d5cb
commit b00ad65b08
4 changed files with 24 additions and 20 deletions

View File

@@ -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))