Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

smplog

finboxio203MIT0.2.0

Simple logging module to stdout. Machine and human readable.

log

readme

smplog

A simple logging module to stdout. Machine and human readable.

Smplog does nothing but provide a simple, standard api for generating human-readable log lines that can be enriched with machine-parseable json metadata. It's primarily intended for use-cases where you have an external log aggregator (e.g. docker + ELK/fluentd/etc) and want effortless log analytics, but also easy-to-understand live tails. Smplog makes the assumption that log routing is beyond the scope of your application's responsibility and thus does not support multi-transport routing, or destinations other than stdout.

Smplog messages are written in the following format:

[${level}] ${message} smplog::${metadata.json}

Easy to read, easy to determine severity, easy to include relevant metadata.

Smplog supports 4 different log levels: info, debug, warn, and error. To suppress messages below a certain level, you can initialize your log with a particular level, or set process.env.LOG_LEVEL globally.

Usage

var Log = require('smplog')
var log = Log()
log.info('this is a standard info message', { tag: 'info-message' })

=====

[info] this is a standard info message smplog::{"tag":"info-message"}

Defaults

You can initialize a log instance with default tags that will be included in the json portion of each message written by that log:

var log = Log({ request_id: 'bea91083fa003d' })
log.info(`request started at ${Date.now()}`)

=====

[info] request started at 1474397320662 smplog::{"request_id":"bea91083fa003d"}

Tags

Defaults can be added to a logger after initialization by tagging it:

var log = Log()
log.tag({ tag_name: 'tag' })
log.info('tagged message')

// log.tags === { tag_name: 'tag' }

=====

[info] tagged message smplog::{"tag_name":"tag"}

Options

You can also pass options into the log constructor to overwrite the default log level or log output function:

var log = Log({ tag: 'errors' }, { level: 'error', log: console.log })

Note

The log property is exposed primarily for testing. Smplog isn't intended to be used with alternative transports. If you want something more complex, there are lots of great fully-featured logging libraries on npm.

changelog

0.2.0 / 2024-07-18

  • Fix timestamp bug & improve multiline logs
  • Update changelog

0.1.2 / 2020-11-16

  • Fix missing tags in payload when using custom log function

0.1.1 / 2020-11-14

  • Remove chai dependency

0.1.0 / 2020-11-14

  • Multiline improvements
  • Console intercept support
  • Timestamp support
  • smplog:: prefix for payload parseability
  • Update History
  • Update package-lock
  • add package-lock.json
  • Add option to clone with additional tags

0.0.11 / 2019-07-06

  • Add option to clone with additional tags

0.0.10 / 2017-02-03

  • update dependencies

0.0.9 / 2017-02-03

  • support automatic detail logging of errors

0.0.8 / 2016-11-28

  • make padding after level uniform so messages line up

0.0.7 / 2016-11-28

  • safe stringify for circular references

0.0.6 / 2016-11-28

  • update dev deps
  • dim log metadata

0.0.5 / 2016-10-25

  • add tag support

0.0.4 / 2016-10-11

  • update colors and add option to suppress metadata output

0.0.3 / 2016-09-21

  • add color support

0.0.2 / 2016-09-20

  • Add readme, history

0.0.1 / 2016-09-20

  • Initial commit