A simple adapter for using Zerolog with the Echo web framework.
Complete. Latest commit timestamp might be old - that's okay.
Steal a complete example from this file or try go run ./demo
for a quick start.
import (
"github.com/kofalt/echotozero"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog"
)
func main() {
// Web framework
e := echo.New()
e.HideBanner = true
// Create or use any zerolog logger
zl := zerolog.New()
adapter := echotozero.New(zl)
// Log echo messages + http queries
e.Logger = adapter
e.Use(echotozero.Middleware(adapter))
}
You can also steal middleware.go
and mess with which request details are logged.
This repo is an updated fork of Lecho with a few improvements:
- Simplifed surface area
- Easier to read middleware
- Removed context fiddling
- Added a log level to echo's messages when it lacks one
- Punt more features directly to zerolog
- Updated for more recent golang, actions, etc
There's also a large golang logging discussion going on that might influence both libraries in the future.
This will hold the two together for now.
The very first message echo prints is without a level:
7:51AM ??? ⇨ http server started on [::]:8080
Zerolog supports this just fine, but it would be nice to have everything leveled. This message happens because the echo interface demands Output() io.Writer
and, for some reason, uses that to print its startup message. Could probably be fixed by messing with echo.