I want to make global logger.
Can I make global logger? (To access every pacakges)
I want to make global logger.
Can I make global logger? (To access every pacakges)
Packages can have global variables:
package somepackage
import "log"
var (
Log *log.Logger = log.New(os.Stderr, "", log.LstdFlags)
)
Notice that I capitalized Log
. This means it is exported
(think public
in other languages).
In general though, using globals is discouraged. I would recommend thinking of a different pattern.