Plugable JavaScript logging.
$ bower install lumberjack
$ npm install lumberjackjs
Create one master instance if you'd like, or many instances for each system.
var log = Lumberjack();
Logging is off by default to avoid memory leaks and conserve script performance. There are several options to control logging:
// Update localStorage then refresh the page..
localStorage.lumberjack = 'on';
// ..or force logging on when creating a new instance..
var log = Lumberjack(true);
// ..or turn logging on/off during runtime.
log.enable();
log.disable();
Each log entry is tied to a channel and is created on the fly. This data can be an Object, String, Number, or Boolean.
log('signin', 'User has finished signing in.');
Log data may be reset manually for either a single channel or the entire log.
// Clears all log data.
log.clear();
// Clears only the 'a-channel' data.
log.clear('a-channel');
You can attach side-effects to your log channels for analytics tools. The data object is whatever data gets logged when the event trips. You can even attach multiple callbacks to the same channel.
log.on('contentload', function (data) {
analytics.report(data);
});
Define your behavior once and trigger it multiple times.
log('contentload', {
how: 'scroll',
speed: 851
});
Get the logging information you care about with timestamps of when it happened. Every log entry has a timestamp so you can tell when events happened.
log.readback('gallery');
log.readback('gallery', true); // Pretty-print
Quickly check on what log channels are in use.
log.readback.channels(); // Array of channel names
log.readback.channels(true); // Pretty-print
The master record contains all log entries in order.
log.readback.master();
log.readback.master(true); // Pretty-print
You can disable all existing callbacks for a single channel.
log.off('scroll');
All log entries take the form:
{
time: // timestamp when entry was logged
data: // the logged data
channel: // channel of entry
id: // id of entry in master record
}
- See: http://cobbdb.github.io/lumberjack/
- See: http://github.com/cobbdb/lumberjack
- License: MIT