1 回答
TA贡献1825条经验 获得超4个赞
我相信您想将以下字段设置为 true 以在附加 TTY 的情况下自己运行时启用时间戳。
从logrus.TextFormatter文档:
// Enable logging the full timestamp when a TTY is attached instead of just
// the time passed since beginning of execution.
FullTimestamp bool
调整您提供的示例:
package main
import (
"github.com/Sirupsen/logrus"
)
func main() {
customFormatter := new(logrus.TextFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05"
logrus.SetFormatter(customFormatter)
logrus.Info("Hello Walrus before FullTimestamp=true")
customFormatter.FullTimestamp = true
logrus.Info("Hello Walrus after FullTimestamp=true")
}
产生:
$ go run main.go
INFO[0000] Hello Walrus before FullTimestamp=true
INFO[2016-03-24 20:18:56] Hello Walrus after FullTimestamp=true
- 1 回答
- 0 关注
- 368 浏览
添加回答
举报
