Menu

#11 FormattedMessage messes up native object formatting in Chrome

open
Tim Down
None
5
2014-06-28
2014-06-27
No

I thought issue 4 was still open, but after looking at the code, I see that it has in reality been fixed. But I still see stuff like "[[anonymous]] hello, world [object Object]" in my logs, which is why I thought it was still not done.

The offender seems to be this bit of code:

    var getFormattedMessage = function() {
        var formattedMessage = appender.getLayout().formatWithException(loggingEvent);
        return (typeof formattedMessage == "string") ? [formattedMessage] : formattedMessage;
    };

It formats pieces which are not strings. Not nice. I could create a patch, but it would be easier if you got the project on github :p

Discussion

  • Carl-Erik Kopseng

    Made a patch that makes BrowserConsoleAppender use the native formatting for logging arguments that are not strings. Makes the logger a kind of drop-in replacement for console.log

     
  • Tim Down

    Tim Down - 2014-06-28

    Just to be clear, are you using PatternLayout? There is no issue if you use the default layout, which is NullLayout. PatternLayout, in common with all built-in layouts other than NullLayout, produces a single string from a logging event. Given that that is what it has always done, I'm not convinced changing it to return an array of formatted messages is the correct approach. If you want to use PatternLayout in conjunction with BrowserConsoleAppender and pass objects to the browser console, I think I'd prefer creating a new layout, which is relatively simple.

     

    Last edit: Tim Down 2014-06-28

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.