質問

I have a project that has JavaScript in 2 places. One is using node.js on the server-side while the other is obviously the browser JavaScript. I am required to support any browser and I'd like to have a single logging framework for all of them. I picked log4js which works great for logging strings but for objects it has a bit of difficulty.

In node when I do Logger.debug(someObject); I get a beautiful printout of the object. When I try to do this with my browser JavaScript I get [object Object] which is useless.

Anyone know how to do this?

(node is using the terminal as the output console and the browser JavaScript is using the Browser's (Chrome) Console)

役に立ちましたか?

解決

log4js is still pretty young in terms of development. I would modify the source code around line 1795 in "doAppend"

if(typeof(loggingEvent.message) === 'object')
    return window.console.log(loggingEvent.level.levelStr + " - %o", loggingEvent.message);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top