Lesson 26 of 60 · Go
Logging with `log` and Structured Logging (`zap`)
Duration: 15 minutes
Simple Logging
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
The standard library log provides basic logging.
log.Println("Server started")
log.Fatalf("fatal error: %v", err)
Structured logging – zap
$ go get go.uber.org/zap
import "go.uber.org/zap"
func main() {
logger, _ := zap.NewProduction()
defer logger.Sync()
sugar := logger.Sugar()
sugar.Infow("request received", "method", "GET", "path", "/api")
}
zap offers high‑performance, leveled, and context‑aware logging.