Simple go-chi logging middleware for zap
go get github.com/treastech/logger
package main
import (
l "github.com/treastech/logger"
"github.com/go-chi/chi"
"go.uber.org/zap"
"net/http"
)
func main() {
logger, _ := zap.NewProduction()
defer logger.Sync() // flushes buffer, if any
r := chi.NewRouter()
// instead of
// r.Use(middleware.Logger)
// use
r.Use(l.Logger(logger))
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("welcome"))
})
http.ListenAndServe(":3000", r)
}
{"level":"info","ts":1530826215.6541932, "msg":"Served","proto":"HTTP/1.1","path":"/","lat":0.032019407,"status":200,"size":7,"reqId":"localhost/FsNkQGYAQA-000036"}