I put this in util.js in all of my projects:
if (window.console) {
logger.useNativeConsole = false;
// make the default logger log to firebug (log objects, not just strings)
logger.addListener('firebug', null, function (msg) {
var func = null;
switch (msg.level) {
case 'DEBUG': func = console.debug; break;
case 'INFO': func = console.info; break;
case 'ERROR': func = console.error; break;
case 'FATAL': func = console.error; break;
case 'WARNING': func = console.warning; break;
default: func = console.log;
}
func.apply(console, extend([msg.level+":"], msg.info));
});
}
Seems to work with all versions of MochiKit and FireBug I generally
used and doesn't cause problems on other browsers (although I can't
say for Opera).
Arnar
On 1/18/07, Chamius <[EMAIL PROTECTED]> wrote:
The new Firebug 1.0 Beta supports sending objects to its console.log
and then being able to browse them in the GUI. This is very useful, but
MochiKit currently flattens out the objects to a string before passing
them to the console.log.
A quick simple fix:
First:
if (this.useNativeConsole) {
// JCHAM: pass msg object instead of str
this.logToConsole(msg);
}
...
Then:
/** @id MochiKit.Logging.Logger.prototype.logToConsole */
logToConsole: function (msg) {
// ---- JCHAM: Firebug console.log object
if (console && console.log) {
// Firebug!
var level = msg.level.toLowerCase();
var f = console[level]? console[level] : console.log;
f.apply(console, msg.info);
return;
}
// ---- JCHAM: From here convert msg into a string, as orig
var msg = msg.level + ": " + msg.info.join(" ");
if (typeof(window) != "undefined" && window.console
&& window.console.log) {
...
This might break Safari and maybe won't work with other versions of
Firebug. Not really sure yet how if there is a way to detect the
presence of Firebug or previous versions of Firebug (how did
console.log behave in previous versions of Firebug?). More on that when
I get to it. Alternatively we could write a separate listener or Logger
class.
Jaime
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---