1 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個贊
我相信您想將以下字段設(shè)置為 true 以在附加 TTY 的情況下自己運(yùn)行時啟用時間戳。
從logrus.TextFormatter文檔:
// Enable logging the full timestamp when a TTY is attached instead of just
// the time passed since beginning of execution.
FullTimestamp bool
調(diào)整您提供的示例:
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")
}
產(chǎn)生:
$ 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 關(guān)注
- 308 瀏覽
添加回答
舉報(bào)