github.com/uber-go/zap
This package has a good security score with no known vulnerabilities.
Community Reviews
Industrial-strength logging with excellent performance and type safety
The initialization experience is smooth with sensible presets like NewProduction() and NewDevelopment() that work out of the box. Custom configurations via zapcore give you precise control over encoders, outputs, and sampling without fighting the framework. Error messages are clear when field types mismatch, and the stack trace capture integrations work reliably.
One gotcha: remembering to call logger.Sync() before shutdown isn't obvious from basic examples. The structured logging approach also requires team buy-in since it's a departure from fmt.Printf patterns. Documentation is comprehensive with good examples, though finding specific zapcore customization patterns sometimes requires digging through issues.
Best for: High-throughput production services where logging performance matters and you want compile-time type safety.
Avoid if: You're building small scripts or prototypes where printf-style logging simplicity outweighs performance concerns.
Fast structured logger with solid defaults, requires careful sanitization
From a security perspective, Zap doesn't automatically sanitize sensitive data - you must be deliberate about what you log. It won't redact passwords, tokens, or PII unless you handle it yourself. The structured format helps since you control field names, but it's easy to accidentally log request bodies or headers containing secrets. Error logging can expose stack traces with internal paths, which is fine for internal logs but needs filtering if logs go to third parties.
The library follows secure defaults: no eval, no external dependencies beyond Uber's own packages, and predictable behavior. TLS/crypto isn't applicable here. My main caution is around log injection - user input in log messages needs validation to prevent log forging, though the structured API mitigates this compared to printf-style logging.
Best for: High-performance production services where you need structured logging and can implement your own sensitive data sanitization patterns.
Avoid if: You need automatic PII redaction out of the box or are working with developers unfamiliar with secure logging practices.
Production-grade structured logging with exceptional performance characteristics
The structured logging API is well-designed with strongly-typed field constructors (zap.String, zap.Int, etc.) that prevent reflection overhead. The sampling and level-based logging work flawlessly under load. Hook integration for custom outputs or metric emission is straightforward. Configuration via JSON/YAML works reliably, though I prefer programmatic setup for better type safety.
One gotcha: you must call logger.Sync() on shutdown or risk losing buffered logs. The SugaredLogger's Printf-style API is tempting but adds allocations—stick with the structured API in hot paths. Error handling is clean with logger.With() for context propagation. Overall, it's remarkably stable across versions with minimal breaking changes.
Best for: High-throughput services where logging performance matters and structured observability is required.
Avoid if: You need simple Printf-style logging and don't care about allocation overhead or structured output.
Sign in to write a review
Sign In