I'm using the following stub to protect against leaving console.log statements in a production application:
// Protect against IE8 not having developer console open.
var console = console || {
"log": function () {
},
"error": function () {
},
"trace": function () {
}
};
This works fine in the sense that it prevents exceptions from being thrown when I call console.log in IE8 without the developer tools open. However, I dislike the fact that if I open dev. tools after the code has loaded -- I still don't see my log messages.
Is it possible to have both? My attempts have led me to infinite recursions of console.log calls. I also found this: http://log4javascript.org/ but I'd rather not unless entirely necessary
EDIT: To clarify: I simply want to not throw an exception if dev. console isn't open, but use the console if it is opened later.