sirupsen /logrus

Structured, pluggable logging for Go.

★ 25,767⑂ 2,342👁 294⑃ 881● 720▤ 23
GoMITCreated 2013-10-16
下载:v1.10.2v1.10.2 ↓1.10.22026-08-25
+1
日增长
+3
周增长
+3
月增长
25,767
stars
2,342
forks
294
watchers
881
prs
720
issues
23
releases

README

Logrus   

Logrus is a structured logger for Go (golang), completely API compatible with
the standard library logger.

Logrus is in maintenance mode. The project focuses on security, bug fixes,
and performance improvements. New features are not planned, aside from changes
required to provide interoperability with other logging ecosystems (e.g., Go's
log/slog).

I believe Logrus' biggest contribution is to have played a part in today's
widespread use of structured logging in Golang. There doesn't seem to be a
reason to do a major, breaking iteration into Logrus V2, since the fantastic Go
community has built those independently. Many fantastic alternatives have sprung
up. Logrus would look like those, had it been re-designed with what we know
about structured logging in Go today. Check out, for example,
[Zerolog][zerolog], [Zap][zap], and [Apex][apex].

[zerolog]: https://github.com/rs/zerolog
[zap]: https://github.com/uber-go/zap
[apex]: https://github.com/apex/log

Nicely color-coded in development (when a TTY is attached, otherwise just
plain text):

!Colored

With logrus.SetFormatter(&logrus.JSONFormatter{}), for easy parsing by logstash
or Splunk:

json lines
{"animal":"walrus","level":"info","msg":"A group of walrus emerges from the ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"}
{"level":"warning","msg":"The group's number increased tremendously!","number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297 -0400 EDT"}
{"animal":"walrus","level":"info","msg":"A giant walrus appears!","size":10,"time":"2014-03-10 19:57:38.562500591 -0400 EDT"}
{"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the ocean.","size":9,"time":"2014-03-10 19:57:38.562527896 -0400 EDT"}
{"level":"fatal","msg":"The ice breaks!","number":100,"omg":true,"time":"2014-03-10 19:57:38.562543128 -0400 EDT"}


With the default logrus.SetFormatter(&logrus.TextFormatter{}) when a TTY is not
attached, the output is compatible with the
logfmt format:

bash
time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8
time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true
time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4
time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009
time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" animal=orca err="It's over 9000!" number=100 omg=true size=9009


To ensure this behaviour even if a TTY is attached, set your formatter as follows:

go
logrus.SetFormatter(&logrus.TextFormatter{
    DisableColors: true,
    FullTimestamp: true,
})


 Logging Method Name

If you wish to add the calling method as a field, instruct the logger via:

go
logrus.SetReportCaller(true)


This adds the caller as 'method' like so:

json
{"

Top issues

Latest release

v1.10.2 v1.10.2 2026-08-25
Logrus v1.10.2

This is a small maintenance release that updates github.com/stretchr/testify to v1.12.1, removing the legacy gopkg.in/yaml.v3 dependency from Logrus' dependency graph. There are no functional changes in this release.

Dependency Changes

- update github.com/stretchr/testify to v1.12.1


Full Changelog: https://github.com/sirupsen/logrus/compare/v1.10.1...v1.10.2

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON