Skip to content

Instantly share code, notes, and snippets.

@cyrusdavid
Created November 24, 2013 12:22
Show Gist options
  • Save cyrusdavid/7626670 to your computer and use it in GitHub Desktop.
Save cyrusdavid/7626670 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Lumberjack Demo Page</title>
<script type="text/javascript" src="lumberjack.js"></script>
<script type="text/javascript">
console.log('Lovely day isn\'t it?');
console.stream('dog').info('Hooooooooooowl!!!');
console.dir({temp: 85, sunny: true, hourly: [65, 70, 75, 80, 85]});
//the two statements below are equivalent
console.stream('cat').off();
console.off('cat');
console.stream('cat').warn('You are out of catnip!'); //should not see this since the 'cat' stream is off
console.stream('dog').info('Woof! Woof!');
//the two statements below are equivalent
console.stream('cat').on();
console.on('cat');
console.stream('cat').warn('Um guys? I think I just heard a dog.');
console.stream('cat').warn('Hiss!');
console.stream('cat').error('Here he comes. Run!');
console.log('I would like to see everything the cat said.');
console.stream('cat').logs();
console.log('How about everything the dog said?');
console.stream('dog').logs();
</script>
</head>
<body>
<p>Open your browser console...</p>
</body>
</html>
(function () {
var opts = {enabled: true, logging: true}, streams = {}, stream, console;
//override window.console
console = window.console;
window.console = {};
//internal use only
function log(args, type) {
if (streams[stream].enabled) {
console[type].apply(console, argumentsToArray(args));
}
if (opts.logging) {
streams[stream].logs.push(argumentsToArray(args));
}
stream = undefined;
};
function argumentsToArray(arguments) {
return Array.prototype.slice.call(arguments, 0);
};
//console enhancements
window.console.stream = function (name) {
stream = name;
if (streams[stream] == undefined) {
streams[stream] = {enabled: opts.enabled, logs: []}
}
return window.console;
};
window.console.on = function (name) {
streams[name || stream].enabled = true;
};
window.console.off = function (name) {
streams[name || stream].enabled = false;
};
window.console.logs = function (name) {
return streams[name || stream].logs;
}
//console overrides
window.console.log = function () {
log(arguments, 'log');
};
window.console.dir = function () {
log(arguments, 'dir');
};
window.console.info = function () {
log(arguments, 'info');
};
window.console.warn = function () {
log(arguments, 'warn');
};
window.console.error = function () {
log(arguments, 'error');
};
window.console.stream(); //init the default stream
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment