How can I make log4js print objects like console.log

I have a project with JavaScript in 2 locations. One is using node.js on the server side and the other is obviously a JavaScript browser. I have to support any browser and I would like to have a single logging framework for all of them. I chose log4js, which works great for writing strings, but for objects, it's a little difficult.

In node, when I do Logger.debug(someObject);

, I get a nice printout of the object. When I try to do this with my JavaScript browser, I get [object Object], which is useless.

Does anyone know how to do this?

(node ​​uses terminal as output console, and browser JavaScript uses browser console (Chrome))

+3


source to share


1 answer


log4js is still pretty young in terms of development. I would change the original code on line 1795 to "doAppend"



if(typeof(loggingEvent.message) === 'object')
    return window.console.log(loggingEvent.level.levelStr + " - %o", loggingEvent.message);

      

+3


source







All Articles