I am writing a rather large JavaScript software. I need to trace calls, log events, debug actions, while maintain performance and portability across browsers.
Webkit and Firebug both offer console object with methods like trace(), log(), error(), warning(), etc. They are great, but what do I do when the browser is IE or Opera?
Imagine having a big application, you surely want to see all initializations it is doing, events it is making, etc., thus I make it log those. However, if I just log those, the logging will not work in browsers that do not have console registered in the DOM. I could create a wrapper object:
MyNamespace.Console = {};
MyNamespace.Console.log = function(value) {
if (console!==undefined) {
console.log(value);
}
else {
// What should I do to log events on other browsers?
}
}
The above makes so no problems occur on IE / Opera, but how do I log with IE (one really needs logging with IE!).
Also, if I plant logs everywhere in my application, does it slow me down when it is being run on a production environment? Should I have a switch DEBUG on/off and a simple check before logging that if DEBUG===true, then log?
What about systems like Closure Compiler, can you make them to remove logging?
What if there is an error while running on production environment and logging has not happened, how do you debug/find the problem? And in fact, do you ever send JavaScript error logs to you (developer), to make sure your clients are not having problems? How does that work out?
I appreciate any feedback/comments on debugging/logging with JavaScript, this is my first time writing a huge JavaScript application, and frankly, I am not sure what should I do about this... debugging and logging in JavaScript seems a bit unfinished.