Use nanosecond granularity timestmaps in log messages

Signed-off-by: Stephen J Day <stephen.day@docker.com>
pull/347/head
Stephen J Day 2015-04-10 13:56:19 -07:00
parent 85de3967aa
commit e10094141f
1 changed files with 16 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import (
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
"time"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/Sirupsen/logrus/formatters/logstash" "github.com/Sirupsen/logrus/formatters/logstash"
@ -196,13 +197,24 @@ func configureLogging(ctx context.Context, config *configuration.Configuration)
log.SetLevel(logLevel(config.Log.Level)) log.SetLevel(logLevel(config.Log.Level))
switch config.Log.Formatter { formatter := config.Log.Formatter
if formatter == "" {
formatter = "text" // default formatter
}
switch formatter {
case "json": case "json":
log.SetFormatter(&log.JSONFormatter{}) log.SetFormatter(&log.JSONFormatter{
TimestampFormat: time.RFC3339Nano,
})
case "text": case "text":
log.SetFormatter(&log.TextFormatter{}) log.SetFormatter(&log.TextFormatter{
TimestampFormat: time.RFC3339Nano,
})
case "logstash": case "logstash":
log.SetFormatter(&logstash.LogstashFormatter{}) log.SetFormatter(&logstash.LogstashFormatter{
TimestampFormat: time.RFC3339Nano,
})
default: default:
// just let the library use default on empty string. // just let the library use default on empty string.
if config.Log.Formatter != "" { if config.Log.Formatter != "" {