Golang global logging using uber zap

Jim Kang
1 min readMar 24, 2021

so you want to use the logger from go.uber.org/zap globally, and there are several ways of doing it: (for shortest way jump to #4)

1. pass-it-down

(just too many to pass it down and you know how)

2. Injection

func main() {
logger, _ := zap.NewProduction()
otherPackage1.Logger = logger
otherPackage2.Logger = logger
.... // tedious >_<
}
// other package
package otherPackage1
var Logger *zap.Logger
...
func…

--

--

Jim Kang

love writing bit sized programming memo, acoustic guitarist, proud daddy of 5 and great listener (to my kids)