2 回答

TA貢獻1805條經驗 獲得超9個贊
我不得不刪除/go/pkg/mod/github.com/...
解決問題的路徑中的模塊。顯然在創建模塊或最初從 github 中提取代碼時出了點問題。
之后我go get
再次使用我的 logrus lib,它按預期工作。

TA貢獻1854條經驗 獲得超8個贊
我認為 logrus 模塊很好,您只是缺少“log.WithFields”定義。
main.go 文件:
//Source : https://github.com/sirupsen/logrus
//logrus version : require github.com/sirupsen/logrus v.1.2.0
//go version go1.11.2 linux/amd64
package main
import (
//Go package
"os"
"fmt"
log "github.com/sirupsen/logrus"
)
//Checking if the logout file exist
//Just to show the Fatal tag.
func Exists(name string) bool {
? ? ? ? _, err := os.Stat(name)
? ? ? ? return !os.IsNotExist(err)
}
func main() {
? ? ? ? fmt.Println("I'am the main here ... all begin ...")?
? ? ? ? log.WithFields(log.Fields{"main": "main process",}).Info("Initialization.")
? ? ? ? log.WithFields(log.Fields{"main": "...some codes....",}).Warn("Nothting here yet.")
? ? ? ? log.WithFields(log.Fields{"main":"main process",}).Info("It's done. Thanks.")
? ? ? ? //The check here (it's just for demo) so you can see the others tags
? ? ? ? if Exists("paht/to/mylogoutfile") == false {
? ? ? ? ? ? ? ? log.WithFields(log.Fields{"main": "Checking logoutputfile path.",}).Fatal("Mising the Logout file.")
}
? ? ? ? //fmt.Println("This is the end Thankyou for using this. :) ")
? ? ? ? }
go.mod 文件:
module logrustest
require github.com/sirupsen/logrus v1.2.0 // indirect
輸出 :
- 2 回答
- 0 關注
- 167 瀏覽
添加回答
舉報