gpt4 book ai didi

go - Logrus时间戳(以毫秒为单位)

转载 作者:行者123 更新时间:2023-12-01 22:17:25 58 4
gpt4 key购买 nike

使用最新版本的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以微秒/毫秒精度打印时间戳吗?

最佳答案

正如@Flimzy指出的那样,我使用的时间格式无效。

我已经固定使用以下时间格式2006-01-02T15:04:05.999999999Z07:00

另一种(更人性化的)时间戳格式可以是以下格式:Jan _2 15:04:05.000000000
有关时间格式的更多示例,请参见此处-> https://golang.org/pkg/time/#pkg-constants

关于go - Logrus时间戳(以毫秒为单位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58753313/

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com