node chalk_用Chalk记录五颜六色的Node.js消息

node chalk

As you work more and more with Node.js, you start to see the value of good logging, especially to the console.  The problem you run into, however, is that constantly adding logged messages means that the most important messages can get lost in the shuffle.  Info messages should look one way and app-killing errors should look another.  The Node.js module to help us accomplish custom formatting of messages?  Chalk!

随着您与Node.js的合作越来越多,您开始看到良好的日志记录的价值,尤其是对于控制台。 但是,您遇到的问题是,不断添加记录的消息意味着最重要的消息可能会在混洗中丢失。 信息消息应该以一种方式出现,而应用程序杀死错误应该以另一种方式出现。 Node.js模块可帮助我们完成消息的自定义格式? 粉笔

Chalk has a very easy to follow, simple to use API.  Here are a few code examples:

Chalk具有非常易于遵循,易于使用的API。 以下是一些代码示例:


const chalk = require('chalk');

// style a string
chalk.blue('Hello world!');

// combine styled and normal strings
chalk.blue('Hello') + 'World' + chalk.red('!');

// compose multiple styles using the chainable API
chalk.blue.bgRed.bold('Hello world!');

// pass in multiple arguments
chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz');

// nest styles
chalk.red('Hello', chalk.underline.bgBlue('world') + '!');


You can chain methods like bold onto color names, and visa versa.  You can also append Chalk'd strings or add them as separate arguments.  Chalk is very flexible without modifying the String prototype which is impressive.

您可以将bold方法链接到颜色名称上,反之亦然。 您还可以附加Chalk字符串或将其添加为单独的参数。 Chalk非常灵活,无需修改String原型,令人印象深刻。

Apparently over 5,000 projects use Chalk and I can see why!  Big problems should come with big colors and lessor debugging information should be less prominent.  Happy coding!

显然有超过5,000个项目使用Chalk,我明白了原因! 大问题应该带有大的色彩,而更少的调试信息应该不那么突出。 编码愉快!

翻译自: https://davidwalsh.name/chalk

node chalk

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值