Use rfc3339 timestamps in telegraf log output

closes #1564

also add unit and benchmark tests
This commit is contained in:
Cameron Sparr
2016-10-11 13:06:17 +01:00
parent 7a9fef80f5
commit 47de43abf3
3 changed files with 68 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import (
"io"
"log"
"os"
"time"
"github.com/influxdata/wlog"
)
@@ -19,8 +20,8 @@ type telegrafLog struct {
writer io.Writer
}
func (t *telegrafLog) Write(p []byte) (n int, err error) {
return t.writer.Write(p)
func (t *telegrafLog) Write(b []byte) (n int, err error) {
return t.writer.Write(append([]byte(time.Now().UTC().Format(time.RFC3339)+" "), b...))
}
// SetupLogging configures the logging output.
@@ -30,6 +31,7 @@ func (t *telegrafLog) Write(p []byte) (n int, err error) {
// interpreted as stderr. If there is an error opening the file the
// logger will fallback to stderr.
func SetupLogging(debug, quiet bool, logfile string) {
log.SetFlags(0)
if debug {
wlog.SetLevel(wlog.DEBUG)
}