How to properly use Winston

独自空忆成欢 提交于 2020-08-03 02:14:21

问题


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:


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);


来源:https://stackoverflow.com/questions/48390531/how-to-properly-use-winston

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!