appcelerator-archive / ampnext-discussion

This is a placeholder repo for discussions and prototyping around the next version of amp.
0 stars 0 forks source link

use logrus more effectively #2

Open subfuzion opened 7 years ago

subfuzion commented 7 years ago

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, 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.

Example:

log.WithFields(log.Fields{
    "service": "stack",
    "request":   "deploy",
    "name": name,
  }).Info("starting stack deployment")

instead of:

log.Printf("starting stack deployment for: %s\n", name)

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.