Logrus: a maintenance-mode structured logger for Go
Logrus is a structured logger for Go, built to be a near drop-in replacement for the standard library's `log` package while adding fields, levels, and hooks. It's a solid, low-risk choice for a codebase that already depends on it, but the project is in maintenance mode: bug fixes and security patches only, no new features. Starting a project today is a different call, and a real reason to look at something still actively developed.
The case for structured logging in Go
Go's standard library `log` package prints plain strings, so debugging a busy service means grepping unstructured text for the one line that matters. Logrus was one of the first Go libraries to attach queryable key-value fields to every log line instead, so a field like `request_id` or `animal` can be filtered on directly in a log aggregator rather than parsed out of a sentence.
What Logrus is
Logrus is a Go package for structured, leveled logging, built as a near drop-in replacement for the standard library's `log` package. Instead of formatting error strings by hand, you attach key-value fields to a log call — `logrus.WithFields(logrus.Fields{"animal": "walrus"}).Info(...)` — and Logrus renders them as logfmt-style text in a terminal, or JSON once you set the `JSONFormatter` for tools like Splunk or Logstash.
Key features
- ✓Fields-based logging via `WithFields`/`WithField`, e.g. `logrus.WithFields(logrus.Fields{"animal": "walrus"}).Info(...)`, instead of hand-built printf strings
- ✓API-compatible with the standard library `log` package, so swapping the import is usually enough to adopt it
- ✓Built-in `TextFormatter` (colorized in a TTY, logfmt-style otherwise) and `JSONFormatter` for log aggregators like Splunk or Logstash
- ✓Seven log levels: Trace, Debug, Info, Warning, Error, Fatal, and Panic
- ✓A hook system for routing entries to services like Airbrake or syslog, plus a `hooks/` directory of built-in hooks
- ✓Can be wrapped as an `io.Writer` via `logger.Writer()`, letting you redirect the stdlib logger or an `http.Server`'s `ErrorLog` through Logrus
- ✓Optional `SetReportCaller(true)` adds the calling method as a field, at a documented 20-40% overhead in the README's own benchmarks
- ✓A `test` hook (`hooks/test`) with `test.NewNullLogger()` for asserting on log output in unit tests without writing to stdout
Installing and importing Logrus
The README doesn't spell out a separate install command. Logrus is a normal Go module, so `import "github.com/sirupsen/logrus"` inside a Go file is what pulls it in, and the toolchain resolves it from `go.mod` on the next build. One documented gotcha: the module's org name was changed to lower-case, so the README warns that the wrong case in the import path causes import conflicts — `github.com/sirupsen/logrus` (lower-case) is the one to use. The simplest usage is the package-level logger (`logrus.WithFields(...).Info(...)`); for multiple independent loggers, `logrus.New()` creates a separate instance with its own `Out`, `Formatter`, and `Level`.
Configuring output, levels, and fields
Logrus ships with sane defaults, so most configuration is a few property assignments before logging starts. `logrus.SetFormatter(&logrus.JSONFormatter{})` switches output to JSON; the default `TextFormatter` colorizes when a TTY is attached and falls back to plain logfmt-style text otherwise, or you can force plain output with `DisableColors: true` and `FullTimestamp: true`. `logrus.SetOutput(os.Stdout)` redirects away from the default stderr — it accepts any `io.Writer`, including an open file. `logrus.SetLevel(logrus.WarnLevel)` filters out anything below that severity across the seven levels (Trace through Panic). For per-call context, `logrus.WithFields(logrus.Fields{"animal": "walrus", "size": 10}).Info(...)` attaches structured key-value data to a single line. `logger.WithFields(...)` also returns a reusable `Entry`, so a request handler can log `request_id` and `user_ip` on every line without repeating the call. Every entry gets three fields automatically: `time`, `msg`, and `level`.
When Logrus shines: hooks, testing, and io.Writer
- •Routing errors to an external service like Airbrake or a syslog daemon via `AddHook`, so `Error`/`Fatal`/`Panic` calls fan out automatically
- •Asserting on log output in unit tests with `test.NewNullLogger()` and `hook.LastEntry()` instead of capturing stdout
- •Redirecting the standard library logger or an `http.Server`'s `ErrorLog` through Logrus by wrapping it with `logger.Writer()`
- •Emitting JSON logs for ingestion by Splunk or Logstash by switching to `JSONFormatter`
Strengths
- ✓Drop-in compatible with the standard library `log` package, so migrating an existing codebase is often just an import swap
- ✓Structured fields (`WithFields`) make log lines queryable in an aggregator instead of just readable in a terminal
- ✓JSON and logfmt-style text formatters are both built in, covering local development and machine parsing without extra packages
- ✓A dedicated `test` hook makes asserting on log output in unit tests straightforward, without capturing stdout
Limitations: maintenance mode and performance
- △Logrus is officially in maintenance mode: the README says only security fixes, bug fixes, and performance work land, with no new features planned aside from interoperability with `log/slog`.
- △Log rotation isn't built in; the README says it should be handled by an external tool like `logrotate(8)`.
- △`SetReportCaller(true)` adds real overhead — the README cites 20-40% in its own benchmarks — so it's off by default and something you opt into deliberately.
- △The README itself points newcomers toward Zerolog, Zap, and Apex as the actively developed alternatives, a signal about where new projects are headed.
Alternatives: Zerolog, Zap, and Apex
Should you use Logrus today?
Whether Logrus makes sense today depends on where a project already stands. A Go service that already imports Logrus has little reason to migrate off it: the API is stable and isn't going to change further. A brand-new project is a different call — the README names Zerolog, Zap, and Apex as the actively developed alternatives it would resemble if redesigned today, and starting fresh on a maintenance-mode library means adopting a frozen feature set on day one.
Frequently asked questions
Logrus is in maintenance mode: the project only takes security fixes, bug fixes, and performance work, and the README states no new features are planned except interoperability with Go's `log/slog`. That's the entire roadmap the README lays out going forward, so treat Logrus as stable rather than evolving.
Logrus is built to be API-compatible with the standard library `log` package, so you can often replace a `log` import with `log "github.com/sirupsen/logrus"` and keep existing calls working. The README presents this as a core design goal, meant to make adoption in an existing codebase low-friction.
Logrus doesn't publish head-to-head benchmarks against Zerolog or Zap in its README. It instead names both as newer alternatives designed around more current ideas about structured logging in Go, without saying which is faster or citing any specific numbers to compare.
Logrus can output JSON logs for aggregation tools: setting `logrus.SetFormatter(&logrus.JSONFormatter{})` renders every field as JSON, which the README says is meant for easy parsing by tools like Logstash or Splunk once the logs reach them.
Logrus does not include built-in log rotation. The README says rotation should be handled by an external program like `logrotate(8)` rather than the application-level logger itself, so you'll need to set that up separately in your deployment.
Logrus ships a `test` hook for this: `test.NewNullLogger()` returns a logger plus a hook, and after logging you can assert on `hook.LastEntry().Message` or `hook.Entries` without the log lines being printed to stdout during the test run.
Related repositories
Curious whether logrus is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about logrus.
