Create a console logger w/ formatting, timestamp, color, namespace
JavaScript
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
docs
lib
test/lib/long-con
.gitignore
.travis.yml
CHANGELOG.md
Gruntfile.js
LICENSE
README.md
component.json
index.js
package.json

README.md

long-con

Create a console logger w/ formatting, timestamp, color, namespace

Build Status

Examples

stdout, timestamp, namespaces

var longCon = require('long-con');.create();
longCon.set('time', true).set('namespace', 'myLib');

var log = longCon.create('cache');

// [Sun, 21 Apr 2013 21:33:20 GMT] myLib cache
log('hit key: %s', 'key-name');

stderr, color, no namespace

// namespace: white foreground, red background
// body: white foreground, green background
var log = longCon.create(null, console.error, 'white.bgRed', 'white.bgGreen');

See cli-color for color names.

Automatic object-specific stack trace

function Klass() {
  this.console = longCon.create();
  this.log = this.console.create(null, console.log);
  this.console.traceMethods('Klass', this, this.log, Klass.prototype);
}
Klass.prototype.foo = function() {
  this.log('foo1');
  this.bar();
  this.log('foo2');
};
Klass.prototype.bar = function() {
  this.log('bar1');
  this.baz();
  this.log('bar2');
};
Klass.prototype.baz = function() {
  this.log('baz');
};
(new Klass()).foo();

Output:

Klass#foo
|    foo1
|    Klass#bar
|    |    bar1
|    |    Klass#baz
|    |    |    baz
|    |    bar2
|    foo2

See traceMethods().

Manual stack trace

var log = longCon.create(null, console.log);
log.push('foo');
log('msg1')
log.push('bar')
log('msg2')
log.pop();
log.pop();
log('msg3');
foo
|    msg1
|    bar
|    |    msg2
msg3

Installation

NPM

npm install long-con

API

Documentation

License

MIT

Tests

npm test