如何在main之外使用Logger

I am using logger package github.com/jcelliott/lumber for logging in go, and I declare and use it like this:

func main() {
log := lumber.NewConsoleLogger(lumber.DEBUG)
...
log.Error("File error: %v
", e)
}

How can I log from functions outside of main? Obviously here log is declared within main and that limits its scope, but I haven't found a way to have global variables in GO, is there a better way than re-declaring the logger in each function?

Declare your global variable like this :

var log lumber.Logger

func anyFunc() {
  log.Error("File error: %v
", e)
}

func main() {
  log = lumber.NewConsoleLogger(lumber.DEBUG)
  anyFunc()
}