作为Node.js开发人员,我仍然对Golang并不陌生,并且一直在Go中进行依赖管理。导入所有依赖项后,我正在使用Go 1.11并应用mod init
。 logrus就是其中之一,它使我无法编译go应用程序。
问题:
我相信问题确实在logrus内部,但是我不知道现在如何获得另一个(有效的)logrus版本,以便我可以再次编译我的应用程序。
/Users/redacted/Documents/redacted3/redacted2>Finished running tool: /usr/local/bin/go vet ./...
/Users/redacted/go/pkg/mod/github.com/sirupsen/logrus@v1.2.0/entry.go:51: undefined: Logger
/Users/redacted/go/pkg/mod/github.com/sirupsen/logrus@v1.2.0/entry.go:54: undefined: Fields
/Users/redacted/go/pkg/mod/github.com/sirupsen/logrus@v1.2.0/entry.go:61: undefined: Level
如何摆脱这些烦人的依赖问题?
相关导入:
log "github.com/sirupsen/logrus"
Go.mod包含
github.com/sirupsen/logrus v1.2.0
答案 0 :(得分:1)
我不得不删除/go/pkg/mod/github.com/...
路径中的模块,从而解决了该问题。在创建模块或最初从github提取代码时,显然出现了问题。
此后,我再次go get
我的logus库,它按预期工作。
答案 1 :(得分:0)
我认为logrus模块很好,您只是缺少“ log.WithFields”定义。请在此处查看文档:{{3}}。下面的代码对我有用。
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
祝你好运:)