golang-echo-zap
Use this skill when adding or configuring github.com/adlandh/echo-zap-middleware/v2 in a Go Echo service.
Use When
- The user wants Zap request logging in an Echo app.
- Code imports
github.com/adlandh/echo-zap-middleware/v2 or needs this middleware configured.
- The task mentions
ZapConfig, Middleware, MiddlewareWithContextLogger, BodySkipper, request/response body logging, or Echo request IDs.
Key Facts
- This middleware targets
github.com/labstack/echo/v5; do not mix it with Echo v4 imports.
- Echo v5 handlers and skippers use
*echo.Context, not echo.Context.
- Import path is
github.com/adlandh/echo-zap-middleware/v2; package name is echozapmiddleware unless aliased.
Middleware(logger, config...) is the normal entrypoint for a *zap.Logger.
MiddlewareWithContextLogger(ctxLogger, config...) is for github.com/adlandh/context-logger extractors.
ZapConfig fills defaults only for nil Skipper and nil BodySkipper; bool and int zero values are meaningful.
LimitHTTPBody: true with LimitSize <= 0 disables body limiting.
BodySkipper does not prevent body capture; it replaces non-empty logged bodies with [excluded].
- Request IDs are logged from request
X-Request-Id first, then from Echo's response header.
Minimal Setup
import (
echozapmiddleware "github.com/adlandh/echo-zap-middleware/v2"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
"go.uber.org/zap"
)
logger, err := zap.NewProduction()
if err != nil {
return err
}
e := echo.New()
e.Use(middleware.RequestID())
e.Use(echozapmiddleware.Middleware(logger))
Body And Header Logging
e.Use(echozapmiddleware.Middleware(logger, echozapmiddleware.ZapConfig{
AreHeadersDump: true,
IsBodyDump: true,
LimitHTTPBody: true,
LimitSize: 500,
Skipper: func(c *echo.Context) bool {
return c.Path() == "/health"
},
BodySkipper: func(c *echo.Context) (skipReqBody, skipRespBody bool) {
if c.Path() == "/upload" {
return true, false
}
if c.Request().Header.Get("Content-Encoding") == "gzip" {
return true, true
}
return false, false
},
}))
Context Logger Setup
import contextlogger "github.com/adlandh/context-logger"
ctxLogger := contextlogger.WithContext(logger)
e.Use(echozapmiddleware.MiddlewareWithContextLogger(ctxLogger))
Implementation Guidance
- Add
middleware.RequestID() before this middleware when generated request IDs should appear in logs.
- Keep body dumping off by default for hot paths; enable
IsBodyDump only when the service can afford body capture.
- Use
BodySkipper for sensitive or binary payloads, but still set LimitHTTPBody and LimitSize for large bodies.
- If changing middleware behavior in this repo, preserve downstream request body replay after capture and update README configuration docs.
Verify
- In this repo, run
go test ./... for a fast check.
- For body limit changes, run
go test -run TestLimitBody ./... and go test -run 'TestMiddleware/TestBodyLimitApplied' ./....
- CI uses
go test -race -coverprofile=coverage.txt -covermode=atomic ./....
Source: adlandh/echo-zap-middleware — distributed by TomeVault.
1---2name: golang-echo-zap3description: Use when adding or configuring github.com/adlandh/echo-zap-middleware/v2 in a Go Echo service.4---56# golang-echo-zap78Use this skill when adding or configuring `github.com/adlandh/echo-zap-middleware/v2` in a Go Echo service.910## Use When11- The user wants Zap request logging in an Echo app.12- Code imports `github.com/adlandh/echo-zap-middleware/v2` or needs this middleware configured.13- The task mentions `ZapConfig`, `Middleware`, `MiddlewareWithContextLogger`, `BodySkipper`, request/response body logging, or Echo request IDs.1415## Key Facts16- This middleware targets `github.com/labstack/echo/v5`; do not mix it with Echo v4 imports.17- Echo v5 handlers and skippers use `*echo.Context`, not `echo.Context`.18- Import path is `github.com/adlandh/echo-zap-middleware/v2`; package name is `echozapmiddleware` unless aliased.19- `Middleware(logger, config...)` is the normal entrypoint for a `*zap.Logger`.20- `MiddlewareWithContextLogger(ctxLogger, config...)` is for `github.com/adlandh/context-logger` extractors.21- `ZapConfig` fills defaults only for nil `Skipper` and nil `BodySkipper`; bool and int zero values are meaningful.22- `LimitHTTPBody: true` with `LimitSize <= 0` disables body limiting.23- `BodySkipper` does not prevent body capture; it replaces non-empty logged bodies with `[excluded]`.24- Request IDs are logged from request `X-Request-Id` first, then from Echo's response header.2526## Minimal Setup27```go28import (29 echozapmiddleware "github.com/adlandh/echo-zap-middleware/v2"30 "github.com/labstack/echo/v5"31 "github.com/labstack/echo/v5/middleware"32 "go.uber.org/zap"33)3435logger, err := zap.NewProduction()36if err != nil {37 return err38}3940e := echo.New()41e.Use(middleware.RequestID())42e.Use(echozapmiddleware.Middleware(logger))43```4445## Body And Header Logging46```go47e.Use(echozapmiddleware.Middleware(logger, echozapmiddleware.ZapConfig{48 AreHeadersDump: true,49 IsBodyDump: true,50 LimitHTTPBody: true,51 LimitSize: 500,52 Skipper: func(c *echo.Context) bool {53 return c.Path() == "/health"54 },55 BodySkipper: func(c *echo.Context) (skipReqBody, skipRespBody bool) {56 if c.Path() == "/upload" {57 return true, false58 }59 if c.Request().Header.Get("Content-Encoding") == "gzip" {60 return true, true61 }62 return false, false63 },64}))65```6667## Context Logger Setup68```go69import contextlogger "github.com/adlandh/context-logger"7071ctxLogger := contextlogger.WithContext(logger)72e.Use(echozapmiddleware.MiddlewareWithContextLogger(ctxLogger))73```7475## Implementation Guidance76- Add `middleware.RequestID()` before this middleware when generated request IDs should appear in logs.77- Keep body dumping off by default for hot paths; enable `IsBodyDump` only when the service can afford body capture.78- Use `BodySkipper` for sensitive or binary payloads, but still set `LimitHTTPBody` and `LimitSize` for large bodies.79- If changing middleware behavior in this repo, preserve downstream request body replay after capture and update README configuration docs.8081## Verify82- In this repo, run `go test ./...` for a fast check.83- For body limit changes, run `go test -run TestLimitBody ./...` and `go test -run 'TestMiddleware/TestBodyLimitApplied' ./...`.84- CI uses `go test -race -coverprofile=coverage.txt -covermode=atomic ./...`.8586---87> Source: [adlandh/echo-zap-middleware](https://github.com/adlandh/echo-zap-middleware) — distributed by [TomeVault](https://tomevault.io).88<!-- tomevault:4.0:skill_md:2026-05-23 -->