Sirupsen/logrus: Difference between revisions
Jump to navigation
Jump to search
(→Idioms) |
|||
(One intermediate revision by the same user not shown) | |||
Line 12: | Line 12: | ||
==Constant String Logging== | ==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'> | <syntaxhighlight lang='go'> | ||
Line 19: | Line 30: | ||
"field2": value2 | "field2": value2 | ||
}).Error("Constant string error message") | }).Error("Constant string error message") | ||
} | |||
</syntaxhighlight> | </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")
}