Skip to content

Commit

Permalink
Use fixed length millisecond timestamp format for logs (#172)
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
  • Loading branch information
sylr authored and brian-brazil committed Feb 19, 2019
1 parent f866ba3 commit 7a3416f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion promlog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,23 @@ package promlog

import (
"os"
"time"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/pkg/errors"
)

var (
// This timestamp format differs from RFC3339Nano by using .000 instead
// of .999999999 which changes the timestamp from 9 variable to 3 fixed
// decimals (.130 instead of .130987456).
timestampFormat = log.TimestampFormat(
func() time.Time { return time.Now().UTC() },
"2006-01-02T15:04:05.000Z07:00",
)
)

// AllowedLevel is a settable identifier for the minimum level a log entry
// must be have.
type AllowedLevel struct {
Expand Down Expand Up @@ -90,6 +101,6 @@ func New(config *Config) log.Logger {
}

l = level.NewFilter(l, config.Level.o)
l = log.With(l, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller)
l = log.With(l, "ts", timestampFormat, "caller", log.DefaultCaller)
return l
}

0 comments on commit 7a3416f

Please sign in to comment.