使用最新版本的logrus
(v1.4.2),我无法在日志格式化程序中设置毫秒/微秒。
在以前的版本(我不记得是哪个版本)中,我只是使用以下时间格式:
Formatter := new(log.TextFormatter)
Formatter.TimestampFormat = "15-01-2018 15:04:05.000000"
Formatter.FullTimestamp = true
Formatter.ForceColors = true
log.SetFormatter(Formatter)
log.SetLevel(log.DebugLevel)
不幸的是,在最新版本中,似乎不再允许使用此时间戳格式。
当我尝试以上述时间格式打印行时,收到以下结果:
17-11-7118 17:35:46.314715
代替正确的一个:
7-11-2019 17:35:46.314715
有人知道如何配置Logrus
来以 microsecond / millisecond 精度打印时间戳吗?
答案 0 :(得分:0)
@Flimzy指出,我使用的时间格式无效。
我已经使用以下时间格式2006-01-02T15:04:05.999999999Z07:00
进行了修复。
另一种(更人性化的)时间戳格式可以如下:Jan _2 15:04:05.000000000
有关时间格式的更多示例,请参见此处-> https://golang.org/pkg/time/#pkg-constants