Middleware for Golang Echo framework that provides integration with Uber´s Zap logging library for logging HTTP requests.
package main
import (
"net/http"
"github.com/berrypay/echozap"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
)
func main() {
e := echo.New()
zapLogger, _ := zap.NewProduction()
e.Use(echozap.ZapLogger(zapLogger))
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))
}
The following information is logged:
- Status Code
- Time
- Uri
- Method
- Hostname
- Remote IP Address
Customization can be made on 2 configurable items:
- Skipper: skip logging based on the given condition
- IncludeHeader: add custom log field based on the provided list of header keys
Usage:
package main
import (
"net/http"
"github.com/berrypay/echozap"
"github.com/labstack/echo/v4"
"go.uber.org/zap"
)
func main() {
e := echo.New()
zapLogger, _ := zap.NewProduction()
e.Use(echozap.ZapLoggerWithConfig(zapLogger, echozap.ZapLoggerConfig{
Skipper: nil,
IncludeHeader: []string{
echo.HeaderXRequestID,
},
}))
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))
}
- Add more customization options.
Contributions, issues and feature requests are welcome!
If this project have been useful for you, I would be grateful to have your support.
Give a ⭐️ to the project, or just:
👤 Bruno Paz
- Website: https://github.com/brpaz
- Github: @brpaz
👤 Sallehuddin Abdul Latif
- Website: https://www.berrypay.com
- Github: @salleh @BerryPay
Copyright © 2019 Bruno Paz.
This project is MIT licensed.