第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Logrus 時間戳格式

Logrus 時間戳格式

Go
楊__羊羊 2021-12-27 16:05:45
我正在嘗試從 Golang 日志包過渡到Logrus。我的問題是關(guān)于如何自定義記錄消息的時間戳格式。默認(rèn)值是自啟動以來的秒數(shù)計(jì)數(shù)器,但我想要“2016-03-24 17:10:15”格式。我的簡單測試代碼是:package mainimport (        "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")}這編譯并運(yùn)行良好,但時間戳格式未更改。任何人都可以提供一些有關(guān)它為什么不起作用的見解嗎?
查看完整描述

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


查看完整回答
反對 回復(fù) 2021-12-27
  • 1 回答
  • 0 關(guān)注
  • 308 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號