Exploit logrus fields and hooks to add more value to our logging.
Rationale
We already use logrus primarily as a drop in replacement for the standard library logger primarily due to its support for logging levels. We can leverage logrus support for structured logging to enhance log analysis / analytics and support for hooks to support exception tracking and alerts.
Fields
logrus supports fields and provides three by default (time, msg, and level). However, these can be augmented with custom fields that can be tremendously valuable for reducing log message parsing when analyzing logs, providing structure and context that may be missing in raw strings.
Proposal
Exploit logrus fields and hooks to add more value to our logging.
Rationale
We already use logrus primarily as a drop in replacement for the standard library logger primarily due to its support for logging levels. We can leverage logrus support for structured logging to enhance log analysis / analytics and support for hooks to support exception tracking and alerts.
Fields
logrus supports fields and provides three by default (
time
,msg
, andlevel
). However, these can be augmented with custom fields that can be tremendously valuable for reducing log message parsing when analyzing logs, providing structure and context that may be missing in raw strings.Example:
instead of:
See here for adding default fields.
Hooks
logrus supports hooks for log levels, which would we can use for exception tracking / alerts. See hooks for details.