3

I have read the docs for logging in node.js using the winston package.

My question: Do I need to add my logging module to every single page that requires logging.. or does winston somehow intercept console.log and console.error.

thanks for your time.

1 Answer 1

5

Normally, you'd need to require your logger in the modules that use it.

However, you can follow the suggestion made by @spmason in the gist logging.js or what @fega suggests in his comment to redefine the properties of the console Object:

console.log = (...args) => logger.info.call(logger, ...args);
console.info = (...args) => logger.info.call(logger, ...args);
console.warn = (...args) => logger.warn.call(logger, ...args);
console.error = (...args) => logger.error.call(logger, ...args);
console.debug = (...args) => logger.debug.call(logger, ...args);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.