simplog

0.2.4 • Public • Published

simplog

The simplest useful log module imaginable.

Writes messages to stdout (as in 12 Factor App) using the node.js util.log and util.format methods.

Installation

npm install simplog

Usage

Supports error, info, warn, debug and a handy event method. It's written in coffee script and you should be too (that was deliberate).

log.error "this is an error"
log.info  "this is informational"
log.warn  "this is a warning"
log.debug "this is a debug message and will only show up if process.env.DEBUG or window.debug is truthy"
log.event "this will log with the type [EVENT] and will only show up if process.env.DEBUG is truthy"

Formatting

It's even possible to use string formatting with it, like:

log.info "that %s looked like %j", object_name, object

Under the covers it's just using node's util.format and supports what you would expect.

Output

As of 0.0.5 the output includes a pid as follows

22 May 22:07:44 - [15794] [ERROR] look ma, an error

If you decide you like the old way, sans pid:

22 May 22:07:44 - [ERROR] look ma, an error

you can make process.env.NOLOGPID truthy and it will go away. If there's something called window in the global scope, we'll skip the PID in any output. Reasonable?

If, for any reason, you want to avoid any log output you can make DISABLE_LOGGING ( an environment variable ) truthy and all logging will be skipped. I find this helpful for testing things that use simplog.

Readme

Keywords

Package Sidebar

Install

npm i simplog

Weekly Downloads

36

Version

0.2.4

License

BSD

Last publish

Collaborators

  • intimonkey