Sirupsen/logrus: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Go Open Source Packages")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
* https://github.com/sirupsen/logrus
=Internal=
=Internal=
* [[Go_Open_Source_Packages#Overview|Go Open Source Packages]]
* [[Go_Open_Source_Packages#Overview|Go Open Source Packages]]
* [[Go_Logging#Open_Source_Logging_Packages|Go Logging]]
=Overview=
Logrus is in maintenance-mode. From the author: ''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, [[Zap]], and Apex.''
=Idioms=
==Constant String Logging==
One field:
<syntaxhighlight lang='go'>
if err != nil {
    logger.WithError(err).WithField("field1", value1).Error("Constant string error message")
}
</syntaxhighlight>
Multiple fields:
<syntaxhighlight lang='go'>
if err != nil {
    logger.WithError(err).WithFields(logrus.Fields{
        "field1":  value1,
        "field2":  value2
    }).Error("Constant string error message")
}
</syntaxhighlight>

Latest revision as of 17:26, 4 September 2024

External

Internal

Overview

Logrus is in maintenance-mode. From the author: 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, Zap, and Apex.

Idioms

Constant String Logging

One field:

if err != nil {
    logger.WithError(err).WithField("field1", value1).Error("Constant string error message")
}


Multiple fields:

if err != nil {
    logger.WithError(err).WithFields(logrus.Fields{
        "field1":   value1,
        "field2":   value2
    }).Error("Constant string error message")
}