Skip to content

Instantly share code, notes, and snippets.

@pete-otaqui
Created September 30, 2011 14:25
Show Gist options
  • Save pete-otaqui/1253892 to your computer and use it in GitHub Desktop.
Save pete-otaqui/1253892 to your computer and use it in GitHub Desktop.
EG-Console
(function () {
var div;
var divId = 'eg-console';
var noop = function () {};
var echo = function (fn, args) {
if (!div) {
div = document.createElement('div');
div.setAttribute('id', divId);
div.setAttribute('style', 'position:absolute;top:0px;right:0px;width:200px;z-index:999;border:1px solid #000;background-color:#fff');
setTimeout(function() {
document.body.appendChild(div);
}, 100);
}
var html = fn + ' : ';
for (var i = 0, ii = args.length; i < ii; i++) {
html += args[i];
if (i < ii - 1) html += ', ';
}
div.innerHTML += '<div>' + html + '</div>';
},
fncs = ['log', 'debug', 'info', 'warn', 'error', 'assert', 'clear', 'dir', 'dirxml', 'trace', 'group', 'groupCollapsed', 'groupEnd', 'time', 'timeEnd', 'profile', 'profileEnd', 'count', 'exception', 'table'];
console = {};
for ( i in fncs ) addConsoleFunc(fncs[i]);
function addConsoleFunc(fName) {
console[fName] = function() {
echo(fName, arguments);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment