Skip to main content
go_logs is a powerful structured logging library for Go that provides comprehensive logging capabilities for modern applications. It offers both a legacy API (v2) for backward compatibility and a modern API (v3) with structured logging, typed fields, and advanced features.

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:
LevelValueDescription
Trace10Detailed execution traces
Debug20Debugging information
Info30Informational events
Warn40Warning messages
Error50Error events
Fatal60Fatal errors (terminates program)
Silent0Disables all logging

Formatters

TextFormatter (development)

Human-readable output with ANSI colors for terminal:
[2026/02/28 17:30:00] INFO connection established host=db.example.com port=5432

JSONFormatter (production)

Structured JSON for log aggregators like ELK, Loki, and Datadog:
{"timestamp":"2026-02-28T17:30:00Z","level":"INFO","message":"connection established","fields":{"host":"db.example.com","port":5432}}

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.

Build docs developers (and LLMs) love