kentor
kentor

Reputation: 18504

What to do if go module is broken

As Node.js developer I am still new to Golang and struggling with the dependency management in Go. I am using Go 1.11 and applied mod init after importing all my dependencies. One of them is logrus which prevents me from compiling my go application.

The problem:

I believe that the problem is indeed inside of logrus, however I don't know how I could now get another (working) version of logrus, so that I can compile my application again.

/Users/redacted/Documents/redacted3/redacted2>Finished running tool: /usr/local/bin/go vet ./...
/Users/redacted/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:51: undefined: Logger
/Users/redacted/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:54: undefined: Fields
/Users/redacted/go/pkg/mod/github.com/sirupsen/[email protected]/entry.go:61: undefined: Level

How can I get rid of these annoying kind of dependency issues?

Relevant import:

log "github.com/sirupsen/logrus"

Go.mod contains

github.com/sirupsen/logrus v1.2.0

Upvotes: 3

Views: 9857

Answers (2)

kentor
kentor

Reputation: 18504

I had to delete the module in my /go/pkg/mod/github.com/... path which fixed the issue. Appparently something gone wrong while creating the module or initially pulling the code from github.

Afterwards I go get my logrus lib again and it worked as intended.

Upvotes: 4

NajlaBioinfo
NajlaBioinfo

Reputation: 579

  • I think the logrus module is fine , you just missing the "log.WithFields" definition. Please take a look to the documentation here : https://github.com/sirupsen/logrus . The code below works for me.

  • The main.go file:

    //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. :) ")
            }
    
  • The go.mod file:

    module logrustest
    
    require github.com/sirupsen/logrus v1.2.0 // indirect
    
  • Output : enter image description here

Good luck :)

Upvotes: 0

Related Questions