Skip to content

Instantly share code, notes, and snippets.

@tcollins
Created March 3, 2010 20:44
Show Gist options
  • Save tcollins/320987 to your computer and use it in GitHub Desktop.
Save tcollins/320987 to your computer and use it in GitHub Desktop.
// Simple logger that will use firebug console log first if available, otherwise simply log to a div
// Requires jquery
// Usage L.log('log this text');
var L = {
logEnabled: true,
log: function(obj)
{
if(L.logEnabled){
try{
console.log(obj);
}catch(ex){
var theConsole = $('#pp-log-console');
var cnt = theConsole.data('cnt');
if(theConsole.length == 0){
theConsole = jQuery("<div/>").attr('id','pp-log-console').appendTo('body');
theConsole.css({ position: 'absolute', left: '15px', top: '40px', border: '5px solid #999'});
topBar = jQuery("<div/>").appendTo(theConsole);
topBar.css({ height: '25px', background: '#4466BB', width: '100%'});
topBar.css({ position: 'absolute', left: '-5px', top: '-30px', zIndex: '20'});
topBar.css({ border: '5px solid #999', borderBottom: '0px none'});
closeBut = jQuery("<a/>").text('close').prependTo(theConsole);
closeBut.css({ position: 'absolute', right: '10px', top: '-20px', color: '#fff', cursor: 'pointer', zIndex: '200'});
closeBut.click(function(e){
$('#pp-log-console').remove();
});
ul = jQuery("<ul/>").appendTo(theConsole);
ul.css({ background: '#000', color: '#00ff00', fontFamily: 'lucida console,monospace' });
ul.css({ height: '100%', width: '100%', overflow: 'auto' });
cnt = 100;
try{ theConsole.draggable({cancel: '#pp-log-console ul'}); }catch(ex){}
try{ theConsole.resizable(); }catch(ex){}
}
cnt++;
theConsole.data('cnt', cnt);
jQuery("<li/>").css({padding: '2px 10px'}).text(cnt + ' | ' + obj).prependTo(theConsole.find('ul'));
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment