Logrus is a Go logging library that stays compatible with the standard library logger while adding structured fields, hooks, and multiple output formats.
Overview
Logrus targets Go programs that want leveled, structured logs instead of long unstructured strings. It exposes the same call patterns as the standard logger so imports can be swapped, and you can add key-value fields that make events easier to search later.
Built-in formatters emit colorized text for terminals, JSON for aggregators, or logfmt-style lines when no TTY is present. Hooks let you fan out messages by level to syslog, metrics systems, or custom sinks. Seven severity levels are supported from trace through panic.
The package can attach default fields to an entry for request-scoped context, optionally record caller method names, register fatal handlers before exit, and act as an io.Writer for redirecting standard library log output. A mutex guards concurrent writes by default.
The maintainers describe the project as in maintenance mode, focusing on security fixes, bugs, and performance rather than new features, while keeping interoperability with Go's newer slog ecosystem in mind.
Key features
- Structured field-based log entries
- JSON, text, and logfmt formatters
- Level-based hooks for external sinks
- Stdlib-compatible logger API
- Optional caller method field
- Built-in test hooks for assertions
- Fatal message handler registration
- Thread-safe concurrent writes
Use cases
- Adding searchable fields to Go services
- Shipping JSON logs to aggregation stacks
- Routing errors to monitoring hooks
- Dropping into existing stdlib log calls