Debugging Javascript on IE

Everyone should know about Firebug for Mozilla by now. I had the problem not being able to use ‘console.log()’ on IE.

Here’s a quick solution, a wonderful package log4javascript by Tim Down.

I used wrapper class to switch between the two on different browsers.

if(navigator.userAgent.indexOf("Firefox") == -1) {
// Create the logger. "mylogger" is the unique name of the logger and
// can be any string.
var log = log4javascript.getLogger("mylogger");// Create a PopUpAppender with default options
var popUpAppender = new log4javascript.PopUpAppender();

// Change the desired configuration options
popUpAppender.setFocusPopUp(true);
popUpAppender.setNewestMessageAtTop(true);

// Add the appender to the logger
log.addAppender(popUpAppender);

var console = Class.create();
console.log = function(s) { log.debug(s);  }
console.debug = function(s) { log.debug(s);  }
console.info = function(s) { log.info(s);  }
console.warn = function(s) { log.warn(s);  }
console.error = function(s) { log.error(s);  }
}

  1. Tim Down

    Version 1.3 of log4javascript released last week has explicit support for Firebug as part of the BrowserConsoleAppender. It also now allows you to log objects, which lets you take advantage of Firebug’s object inspection.

  2. rex

    Thanks, thats great.

Leave a Comment




I am the founder of RoRCraft Ltd., a web consultancy firm that develops usable and speedy web applications for our clients.


Based in Sydney, I travel to Hong Kong and HangZhou China to meet with my team regularly. I love exploring new technologies and business ideas that helps making our world a better place.



An online video conversion tool. It allows everyone to freely convert their videos for ipods, mobiles and flash.


Rails Job


Job board for Ruby and Rails developers.


View Rex Chung's profile on LinkedIn

www.flickr.com

LATEST RUBY JOBS

Embed this on your site?