문제

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