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
Skipper
function 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
msg
field caller
field 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.Context
usingFieldAdder
function. - Errors given as function argument to
panic
can 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.HeaderXRequestID
by 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.HeaderXRequestID
by 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/zap4echo
log, _ := zap.NewDevelopment()
e.Use(
zap4echo.Logger(log),
zap4echo.Recover(log),
)
Then curl it:
curl http://host:port
Configuration 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...
}))