views:

6333

answers:

6

According to this post it was in the beta, but it's not in the release?

+1  A: 

It works in IE8. Open IE8's Developer Tools by hitting F12.

>>console.log('test')
LOG: test
Koistya Navin
A: 

firebug bookmarklet includes console.log

http://getfirebug.com/lite.html

thirsty93
+16  A: 

console.log is only available after you have opened the Developer Tools (F12 to toggle it open and closed). Funny thing is that after you've opened it, you can close it, then still post to it via console.log calls, and those will be seen when you reopen it. I'm thinking that is a bug of sorts, and may be fixed, but we shall see.

I'll probably just use something like this:

function trace(s) {
  if (this.console && typeof console.log != "undefined")
    console.log(s);
  // the line below you might want to comment out, so it dies silent
  // but nice for seeing when the console is available or not.
  else alert(s);
}

and even simpler:

function trace(s) {
  try { console.log(s) } catch (e) { alert(s) }
};
Mister Lucky
That's the sillyst thing I've ever heard...typical MS. Thanks man!
leeand00
No problem, yep it's quite typical. Those fun quirks we must learn to adjust and overcome!
Mister Lucky
Either way you shouldn't be calling console.log blindly because $other-browsers mightn't have it and thus die with a JavaScript error. +1
Kent Fredric
you'll probably want to turn off traces before release anyhow though ;)
Kent Fredric
@Kent Oh for sure!
leeand00
It makes sense not to log without developer tools being open, but making it throw an exception if rather than failing silently is the real confusing decision here.
ehdv
I want to create shims for console.log, etc - similar to how firebug lite used to do. Unfortunately, I can't get this to work in IE8 (since when I test for typeof console == 'undefined' - it always seems to return true).
mckoss
Doesn't Firebug's log statements behave the same way? They're not available until you open Firebug.
Frank Schwieterman
+2  A: 
NSherwin
+5  A: 

It's worth noting that console.log in IE8 isn't a true Javascript function. It doesn't support the apply or call methods.

James Wheare
+1  A: 

If you get "undefined" to all of your console.log calls, that probably means you still have an old firebuglite loaded (firebug.js). It will override all the valid functions of IE8's console.log even though they do exist. This is what happened to me anyway.

Check for other code overriding the console object.