0
我在所有我的go應用程序中使用logrus,最近我開始使用上下文記錄器。現在我想在應用程序的執行路徑中「建立」一個上下文。看下面的例子,它說明了我想要的。Logrus爲contextlogger添加額外字段
package main
import (
"github.com/Sirupsen/logrus"
)
func main() {
logrus.Info("normal logger")
cl := logrus.WithFields(
logrus.Fields{
"extra_field_one": "extra_value_one",
})
// some code here
// here I want to add an additional field to to contextlogger cl.
// How do I do that?
}
編輯
正如ymonad提到的,通過覆蓋contextLogger是可能的。還發現,可以添加一個附加字段:
cl = cl.WithField("key", "value")
感謝;工作正常! –