Skip to content

Commit d47bda9

Browse files
authored
Merge pull request #2490 from thaJeztah/logging_nanosecond_precision
Set default log formatting to use RFC3339Nano with fixed width
2 parents a88b631 + da73b98 commit d47bda9

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

cmd/containerd/command/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ high performance container runtime
4848
`
4949

5050
func init() {
51+
logrus.SetFormatter(&logrus.TextFormatter{
52+
TimestampFormat: log.RFC3339NanoFixed,
53+
FullTimestamp: true,
54+
})
55+
5156
// Discard grpc logs so that they don't mess with our stdio
5257
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard))
5358

log/context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ type (
4242
// and is usually used to trace detailed behavior of the program.
4343
const TraceLevel = logrus.Level(uint32(logrus.DebugLevel + 1))
4444

45+
// RFC3339NanoFixed is time.RFC3339Nano with nanoseconds padded using zeros to
46+
// ensure the formatted time is always the same number of characters.
47+
const RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
48+
4549
// ParseLevel takes a string level and returns the Logrus log level constant.
4650
// It supports trace level.
4751
func ParseLevel(lvl string) (logrus.Level, error) {

0 commit comments

Comments
 (0)