Merge pull request #2490 from thaJeztah/logging_nanosecond_precision

Set default log formatting to use RFC3339Nano with fixed width
This commit is contained in:
Kenfe-Mickaël Laventure 2018-07-24 08:23:59 -07:00 committed by GitHub
commit d47bda91e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -48,6 +48,11 @@ high performance container runtime
` `
func init() { func init() {
logrus.SetFormatter(&logrus.TextFormatter{
TimestampFormat: log.RFC3339NanoFixed,
FullTimestamp: true,
})
// Discard grpc logs so that they don't mess with our stdio // Discard grpc logs so that they don't mess with our stdio
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard)) grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard))

View File

@ -42,6 +42,10 @@ type (
// and is usually used to trace detailed behavior of the program. // and is usually used to trace detailed behavior of the program.
const TraceLevel = logrus.Level(uint32(logrus.DebugLevel + 1)) const TraceLevel = logrus.Level(uint32(logrus.DebugLevel + 1))
// RFC3339NanoFixed is time.RFC3339Nano with nanoseconds padded using zeros to
// ensure the formatted time is always the same number of characters.
const RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
// ParseLevel takes a string level and returns the Logrus log level constant. // ParseLevel takes a string level and returns the Logrus log level constant.
// It supports trace level. // It supports trace level.
func ParseLevel(lvl string) (logrus.Level, error) { func ParseLevel(lvl string) (logrus.Level, error) {