This is a very customizable middleware that provides logging and panic recovery for Echo using Uber's zap. Please see LoggerConfig and RecoverConfig for documentation of configuration fields. Have fun!
- Highly customizable
- There's a
Skipperfunction so you can skip logging of HTTP requests depending on theecho.Context - Error only logging: Logging can be limited to requests resulted in error — requests which either returned an error or has a status code of 3xx, 4xx, or 5xx.
- Custom
msgfield callerfield is not logged by default. Logging can be enabled withIncludeCaller.- You can omit certain log fields for convenience or performance reasons.
- Request IDs are logged. Custom header name can be set with
CustomRequestIDHeader - Custom log fields can be added depending on the
echo.ContextusingFieldAdderfunction. - Errors given as function argument to
paniccan be handled withErrorHandler - Logging of the stack trace can be customized.
- There's a
- Convenient and quick to use
- Performant
- zap4echo is designed to be performant.
- Echo and zap is one of the most performant framework/logger combination in the Go ecosystem.
- Well tested
- 100% test coverage
Please note that in addition, extra fields can be added with FieldAdder function.
- Logger
proto- Protocolhost- Host headermethod- HTTP methodstatus- Status as integerresponse_size- Size of the HTTP responselatency- Time passed between the start and end of handling the requeststatus_text- HTTP status as textclient_ip- Client IP addressuser_agent- User agentpath- URL pathrequest_id- Request ID (Usesecho.HeaderXRequestIDby default. Custom header can be set withCustomRequestIDHeader)referer- Referer
- Recover
error- Error of the panicmethod- HTTP methodpath- URL pathclient_ip- Client IP addressstacktrace(if enabled)request_id- Request ID (Usesecho.HeaderXRequestIDby default. Custom header can be set withCustomRequestIDHeader)
This is a quick cheat sheet. For complete examples, have a look at: basic and full
go get -u github.com/karagenc/zap4echolog, _ := zap.NewDevelopment()
e.Use(
zap4echo.Logger(log),
zap4echo.Recover(log),
)Then curl it:
curl http://host:portConfiguration for customization are documented with comments. For documentation, have a look at LoggerConfig and RecoverConfig
log, _ := zap.NewDevelopment()
e.Use(zap4echo.LoggerWithConfig(log, zap4echo.LoggerConfig{
// Configure here...
}))
e.Use(zap4echo.RecoverWithConfig(log, zap4echo.RecoverConfig{
// Configure here...
}))