simplog
v0.2.4
Published
A very simple logging module. Because all the others are too much. This module relies on the node util module to provide timestamping and formatting of log messages. Messages are written to stdout via util.log.
Downloads
69
Readme
simplog
The simplest useful log module imaginable.
Writes messages to stdout (as in [12 Factor App] (http://www.12factor.net/logs)) 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.