调试node.js代码时,有没有办法在Visual Studio Code(版本1.10.2)的调试控制台中显示颜色(就像在终端中一样)?
要在 Visual Studio 中从 NodeJS 输出彩色消息,您可以在 console.log 方法中使用格式化消息。例如 :
console.log('\u001b[' + 32 + 'm' + 'hello stack' + '\u001b[0m')
如实施于Mocha https://github.com/mochajs/。 32 是颜色代码。您可以在他们的存储库中找到其他颜色代码和使用示例:https://github.com/mochajs/mocha/blob/9e95d36e4b715380cef573014dec852bded3f8e1/lib/reporters/base.js#L48 https://github.com/mochajs/mocha/blob/9e95d36e4b715380cef573014dec852bded3f8e1/lib/reporters/base.js#L48
或者作为日志库,您可以使用,例如pinojs https://github.com/pinojs/pino + 皮诺漂亮 https://github.com/pinojs/pino-pretty模块和您的日志输出将显示如下:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)