【发布时间】:2021-05-04 11:13:40
【问题描述】:
我的日志消息输出有问题。我正在使用 logrus。
我正在使用 VS Code 进行开发,当我调试代码时,日志输出为:
time="2021-05-04T11:52:11+01:00" level=info msg=message
但是当我运行应用程序可执行文件或使用 go run main.go 时,输出是:
INFO[0007] message
我想要第一个输出。
发生了什么?
编辑:
我们需要按照logrus github中的说明设置格式化程序。
【问题讨论】:
-
你试过
To ensure this behaviour even if a TTY is attached, set your formatter as follows: log.SetFormatter(&log.TextFormatter{DisableColors: true, FullTimestamp: true})from:github.com/sirupsen/logrus -
我错过了。是的,这行得通。谢谢@DianBakti
-
请为您自己的问题创建一个答案并标记它,以便其他人知道此问题已解决以及解决方案是什么。