API Reference

Logrus

Structured logging library for Go with levels, fields, formatters and pluggable hooks.

Official Documentation ↗
CompatibilityThis documentation covers version logrus v1.9 / Go 1.20+. Check the official docs for the latest API surface.

Installation

gogo get github.com/sirupsen/logrus

Methods

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.

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.

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.