Logrus
Structured logging library for Go with levels, fields, formatters and pluggable hooks.
Official Documentation ↗logrus v1.9 / Go 1.20+. Check the official docs for the latest API surface.Installation
go get github.com/sirupsen/logrusMethods
No methods match this filter.
Overview
logrus adds structured, leveled logging to Go. Entries carry fields that attach context to messages, and formatters control whether output is human-readable text or machine-parsed JSON.
Core Methods
Package-level functions log at a level, WithField and WithFields create entries with context, and SetFormatter and SetLevel configure output and filtering. Hooks react to specific levels.
Usage Notes
Common Pitfalls
Logging in hot loops or with hooks that perform network calls adds latency. Including secrets in fields leaks them into logs. The library is in maintenance mode, so consider slog for new work.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/sirupsen/logrus@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:44.662Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- For example to send errors to an exception tracking service on Error, Fatal and Panic, info to StatsD or log to multiple places simultaneously, e.g. (https://cdn.jsdelivr.net/gh/sirupsen/logrus@latest/README.md)
- A list of currently known service hooks can be found in this wiki page #### Level logging Logrus has seven logging levels: Trace, Debug, Info, Warning, Error, Fatal and Panic. (https://cdn.jsdelivr.net/gh/sirupsen/logrus@latest/README.md)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/sirupsen/logrus@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:44.662Z.
- Redacts sensitive information like password, apikeys, email, etc. (https://cdn.jsdelivr.net/gh/sirupsen/logrus@latest/README.md)
FAQ
- Is logrus still recommended?
- The project is in maintenance mode and the standard library log/slog now covers structured logging. New code may prefer slog, while existing services often stay on logrus for compatibility.
- How do I log JSON in production?
- Set the JSONFormatter and a level of info, and emit to a stream. JSON output is easy to ingest into log pipelines while text formats suit local development.
- How do hooks work?
- Hooks run on selected levels, for example to send errors to a monitoring service. Keep hook work fast and non-blocking so logging does not slow the request path.
Report a problem with this API docOpens a pre-filled issue on GitHub.