使用最新版本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)
Run Code Online (Sandbox Code Playgroud)
不幸的是,在最新版本中,似乎不再允许这种时间戳格式。
当我尝试使用上述时间格式打印一行时,我收到以下结果:
17-11-7118 17:35:46.314715
而不是正确的:
7-11-2019 17:35:46.314715
有人知道如何配置以微秒/毫秒Logrus精度打印时间戳吗?
正如@Flimzy 所指出的,我使用的时间格式无效。
我已经使用以下时间格式修复了2006-01-02T15:04:05.999999999Z07:00。
另一种(更人性化)时间戳格式如下:Jan _2 15:04:05.000000000
有关时间格式的更多示例,请参阅此处 -> https://golang.org/pkg/time/#pkg-constants