Overview
go_logs v3 brings modern structured logging to Go applications while maintaining 100% backward compatibility with v2. Whether you’re building microservices, APIs, or traditional applications, go_logs provides the tools you need for effective logging.Key features
Structured logging
Log with typed fields using
String(), Int(), Err(), and more. Fields are zero-allocation for high performance.Child loggers
Create child loggers with pre-populated fields that automatically propagate to all log entries.
Multiple formatters
Choose between TextFormatter for development with colors or JSONFormatter for production log aggregators.
Context propagation
Automatically extract and include trace_id and span_id from context for distributed tracing.
Extensible hooks
Send logs to multiple destinations like Slack, Sentry, OpenTelemetry, or syslog using the hook system.
File rotation
Built-in rotating file writer with size-based and time-based rotation, no external dependencies.
Security features
Automatic redaction of sensitive fields like passwords, tokens, and API keys.
Thread-safe
All operations are thread-safe with mutex protection, perfect for concurrent applications.
Log levels
go_logs uses syslog-style log levels with numeric values:| Level | Value | Description |
|---|---|---|
| Trace | 10 | Detailed execution traces |
| Debug | 20 | Debugging information |
| Info | 30 | Informational events |
| Warn | 40 | Warning messages |
| Error | 50 | Error events |
| Fatal | 60 | Fatal errors (terminates program) |
| Silent | 0 | Disables all logging |
Formatters
TextFormatter (development)
Human-readable output with ANSI colors for terminal:JSONFormatter (production)
Structured JSON for log aggregators like ELK, Loki, and Datadog:Quick links
Installation
Get started by installing go_logs in your project
Quick start
Learn the basics with a working example
API reference
Explore the complete API documentation
Examples
See real-world examples and use cases
Use cases
- Microservices: Track requests across services with trace IDs and child loggers
- APIs: Log structured data about requests, responses, and errors
- Background jobs: Monitor job execution with detailed logging
- Production systems: Send logs to aggregators using JSONFormatter
- Development: Debug with colored console output using TextFormatter
Performance
go_logs is designed for high performance with minimal overhead:- Fast-path filtering: 0.32 ns/op
- Field creation: 0.34 ns/op with zero allocations
- TextFormatter: 220.6 ns/op
- JSONFormatter: 249.3 ns/op
- RotatingFileWriter: 16M messages/sec
go_logs v3 is 100% backward compatible with v2. You can upgrade your dependency without changing any existing code.