Note
This project was written by AI (Claude Code).
A Go linter that checks zerolog logging chains for missing context propagation.
zerologlintctx detects cases where a context.Context is available in function parameters but not properly passed to zerolog logging chains via .Ctx(ctx).
Using go install
go install github.com/mpyw/zerologlintctx/cmd/zerologlintctx@latest
zerologlintctx ./...Using go vet
Since zerologlintctx has no custom flags, it can be run via go vet:
go install github.com/mpyw/zerologlintctx/cmd/zerologlintctx@latest
go vet -vettool=$(which zerologlintctx) ./...Using go tool (Go 1.24+)
# Add to go.mod as a tool dependency
go get -tool github.com/mpyw/zerologlintctx/cmd/zerologlintctx@latest
# Run via go tool
go tool zerologlintctx ./...Using go run
go run github.com/mpyw/zerologlintctx/cmd/zerologlintctx@latest ./...Caution
To prevent supply chain attacks, pin to a specific version tag instead of @latest in CI/CD pipelines (e.g., @v0.7.1).
| Flag | Default | Description |
|---|---|---|
-test |
true |
Analyze test files (*_test.go) — built-in driver flag |
Generated files (containing // Code generated ... DO NOT EDIT.) are always excluded and cannot be opted in.
# Exclude test files from analysis
zerologlintctx -test=false ./...Detects zerolog logging chains missing .Ctx(ctx):
func handler(ctx context.Context, log zerolog.Logger) {
// Bad: missing .Ctx(ctx)
log.Info().Str("key", "value").Msg("hello")
// Good: includes .Ctx(ctx)
log.Info().Ctx(ctx).Str("key", "value").Msg("hello")
// Also good: context from log.Ctx() or zerolog.Ctx()
log.Ctx(ctx).Info().Str("key", "value").Msg("hello")
}Detects direct logging calls that bypass the Event chain and cannot propagate context:
func handler(ctx context.Context, log zerolog.Logger) {
// Bad: bypasses Event chain, context cannot be set
log.Print("hello")
log.Printf("hello %s", name)
}The analyzer uses SSA (Static Single Assignment) form to track Event values through variable assignments, conditionals, and closures, ensuring accurate detection even in complex code patterns.
Suppress warnings for a specific line:
func handler(ctx context.Context, log zerolog.Logger) {
//zerologlintctx:ignore - intentionally not passing context
log.Info().Msg("background task")
}The comment can be on the same line or the line above.
- Zero false positives - Prefer missing issues over false alarms
- Type-safe analysis - Uses
go/typesfor accurate detection - SSA-based tracking - Uses SSA form to track Event values through assignments and closures
- Nested function support - Correctly tracks context through closures
- Architecture - Internal design and detection logic
- CLAUDE.md - AI assistant guidance for development
- goroutinectx - Goroutine context propagation linter
- ctxweaver - Code generator for context-aware instrumentation
- gormreuse - GORM instance reuse linter
- zerologlint - General zerolog linting rules
- contextcheck - Detects
context.Background()/context.TODO()usage and missing context parameters
zerologlintctx is complementary to these tools:
zerologlintprovides general zerolog best practicescontextcheckwarns about creating new contexts when one should be propagatedzerologlintctxspecifically warns about not using an available context in zerolog chains
MIT