
Logrus
A structured logger for Go that is API-compatible with the standard library log package.
- Stars
- 25.8k
- Forks
- 2.3k
- Licence
- MIT
- Language
- Go
- Last update
- 1 months ago
- Type
- Library
What it is
Logrus is a logging library for the Go programming language. It records messages with named fields, such as user IDs or request details, so logs can be searched and parsed by tools. It can output colored text for development or JSON for log systems like Logstash or Splunk. The README states the project is now in maintenance mode, focused on security, bug fixes, and performance.
- Replace calls to the standard log package with Logrus to get leveled, structured output
- Write JSON log lines with fields such as request_id and user_ip for parsing by log tools
- Create a logger with default fields attached to every message in a request
- Send error-level messages to an external service using a hook
Great for
- Go developers with existing code that already uses Logrus
- Teams that want a drop-in replacement for the standard log package with structured fields
- Projects that send logs to JSON-based systems such as Logstash or Splunk
- Developers who want to attach extra hooks to send errors to other services
Not ideal for
- New Go projects that want actively developed features, since the README says new features are not planned and it is in maintenance mode; the README points to alternatives such as Zerolog, Zap, and Apex
- Non-Go projects, because it is a Go library
- Projects that need the lowest possible logging overhead, since the README mentions that reporting the caller adds 20 to 40 percent overhead in its tests
How to get it
- 1
Install with a package manager
You'll need: Go
Install the library
go get github.com/sirupsen/logrus - 2
Run it
- Import the package with import "github.com/sirupsen/logrus".
- Call logrus.WithFields with a map of fields, then call Info, Warn, or another level method.
- Optionally call logrus.SetFormatter(&logrus.JSONFormatter{}) to output JSON.
- Run your Go program and check the log output.
- 3
Get the most out of it
- Use logrus.SetFormatter with TextFormatter and DisableColors when output goes to files or other tools.
- Create a logrus.Entry with WithFields to share common fields across related log lines.
- Use logrus.New() to create separate logger instances that write to different outputs.
- Add built-in hooks from the hooks directory to send errors to other services.
Downloads
Strengths
- API-compatible with the Go standard library logger, so switching is simple
- Supports structured fields and both text and JSON output formats
- Supports hooks and custom formatters and outputs
Trade-offs
- The README says the project is in maintenance mode and new features are not planned
- Adding the calling method as a field has measurable performance overhead according to the README
- The README is truncated, so some details on hooks and configuration are not visible here
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| logrus (this) | 25.8k | Library | beginner | 1 months ago | Go developers with existing code that already uses Logrus |
| zerolog | 12.5k | Library | beginner | 23 days ago | Go developers who want machine-readable JSON logs |
| zap | 24.7k | Library | beginner | 2 months ago | Go developers building services that log heavily |
| monolog | 21.4k | Library | intermediate | 5 days ago | PHP developers who need structured logs from an application |
| loguru | 24.2k | Library | beginner | 11 days ago | Python developers who want logging without much setup |
| PySnooper | 16.6k | Library | beginner | 5 months ago | Developers who want quick insight into a function without setting up a full debugger |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.