Menu

#4 Improve multiple arguments logging in Firebug console

closed
nobody
None
5
2014-06-28
2012-02-20
phtrivier
No

In Firebug (potentially in latest version?), it is possible to pass multiple arguments to console.debug, console.log, etc... to have them nicely displayed.
In particular, if you passed an object as the n-th parametter, it will be nicely displayed.

BrowserConsoleAppender does not handle this very nicely ; the default NullLayout returns the arguments of the Logger.log(...) methods as an array of the LoggingEvent, so firebug console will display that : an array.

What is expected would probably be to pass the elements of the array as multiple arguments to the console.log function. This would read something like this in BrowserConsoleAppender.append :

if (window.console.debug && Level.DEBUG.isGreaterOrEqual(loggingEvent.level)) {
window.console.debug.apply(window, formattedMesage);
} ...

instead of

if (window.console.debug && Level.DEBUG.isGreaterOrEqual(loggingEvent.level)) {
window.console.debug(formattedMesage);
} ...

Would that pose any issue (maybe in the case where only one message is passed, I have tested it and it seems to work fine ... or in earlier versions of Firebug ?)

I'll gladly provide the patch if the idea souds ok.

Thanks

PH

Discussion

  • Nick Franceschina

    +1 for this

     
  • Nick Franceschina

    I also added these lines above the IF block:

    if (typeof formattedMesage == 'string') { formattedMesage = [formattedMesage]; }
    formattedMesage = formattedMesage.concat( loggingEvent.messages || [] );

    so I can define a custom PatternLayout... with dates/levels/logger names... and that will become the first argument of the apply() array... with all the logging messages passed in after

     
  • Nick Franceschina

    OK... my last note.... IE7, at least, can't do .apply() on console.log... for whatever reason... so should test for that and fallback to the existing implementation

    right now I'm switching patternLayout if the browser is IE... since I know it can't give me those nice extra params... so for IE I am appending "%m{1}" to the pattern... which breaks out the first level of the object passed in the param.

    not sure if its better to have the application code do that kinda junk, or if it would be better to have the consoleAppender do a "if .apply == undefined, then do a "%m{1}".format() and add to message"

    blah... stupid IE

     
  • Tim Down

    Tim Down - 2012-09-20

    Good suggestion. I'll put this either in the next 1.4 release or 1.5, whichever is sooner.

     
  • Carl-Erik Kopseng

    This seems to have been fixed, so this bug should be closed. Although getFormattedMessage() is messing it up ... :(

     
  • Tim Down

    Tim Down - 2014-06-28
    • status: open --> closed
    • Group: --> Next Release (example)
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.