Ah, the way to do it with no changes to the MochiKit base code, just
using a Listener:
if (console && console.log) {
var logger = MochiKit.Logging.logger;
logger.useNativeConsole = false;
logger.addListener('firebug', null, function(msg) {
var level = msg.level.toLowerCase();
var f = console[level]? console[level] : console.log;
f.apply(console, msg.info);
return;
});
}
On Jan 19, 8:57 am, "Martyn Smith" <[EMAIL PROTECTED]> wrote:
> Here's a patch that I've tested with Firebug 1 beta, and also works
> with browsers that don't support console.log()
>
> Index: Logging.js
> ===================================================================
> --- Logging.js (revision 1250)
> +++ Logging.js (working copy)
> @@ -204,7 +204,28 @@
> this._messages.push(msg);
> this.dispatchListeners(msg);
> if (this.useNativeConsole) {
> - this.logToConsole(msg.level + ": " + msg.info.join(" "));
> + if (typeof(console) == 'object' && console.log) {
> + switch(msg.level) {
> + case 'DEBUG':
> + console.debug.apply(console,msg.info);
> + break;
> + case 'INFO':
> + console.info.apply(console,msg.info);
> + break;
> + case 'WARNING':
> + console.warn.apply(console,msg.info);
> + break;
> + case 'ERROR':
> + console.error.apply(console,msg.info);
> + break;
> + default:
> + console.log.apply(console,msg.info);
> + break;
> + }
> + }
> + else {
> + this.logToConsole(msg.level + ": " + msg.info.join(" "));
> + }
> }
> this.counter += 1;
> while (this.maxSize >= 0 && this._messages.length > this.maxSize) {
>
> On 1/19/07, Arnar Birgisson <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > 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
>
> --
> Martyn
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---