grunt.log 工具方法
发布时间:2023-05-15 14:08:12 所属栏目:教程 来源:
导读:这些方法实际上不记录日志,它们只返回字符串,返回的字符串可以用于其他方法。
grunt.log.wordlist
Returns a comma-separated list of arr array items. arr 数组中的条目将会以逗号分割的形式返回。
grunt
grunt.log.wordlist
Returns a comma-separated list of arr array items. arr 数组中的条目将会以逗号分割的形式返回。
grunt
这些方法实际上不记录日志,它们只返回字符串,返回的字符串可以用于其他方法。 grunt.log.wordlist Returns a comma-separated list of arr array items. arr 数组中的条目将会以逗号分割的形式返回。 grunt.log.wordlist(arr [, options]) options 对象拥有以下属性和默认值: var options = { // The separator string (can be colored). separator: ', ', // The array item color (specify false to not colorize). color: 'cyan', }; grunt.log.uncolor 从字符串中移除所有颜色信息,使其适合检测其 .length 或写入日志文件。、 grunt.log.uncolor(str) grunt.log.wraptext 以 width 个字符为一组将 text 字符串进行分解并添加 \n 字符,除非绝对必要,否则将尽量确保不会从中间截断单词。 grunt.log.wraptext(width, text) grunt.log.table 以 width 个字符为一组将 text 字符串进行分解。Wrap texts array of strings to columns widthscharacters wide. A wrapper for the grunt.log.wraptext method that can be used to generate output in columns. grunt.log.table(widths, texts) 案例 通常的模式是,只有在 --verbose 模式或发生错误时才输出日志,如下所示: grunt.registerTask('something', 'Do something interesting.', function(arg) { var msg = 'Doing something...'; grunt.verbose.write(msg); try { doSomethingThatThrowsAnExceptionOnError(arg); // Success! grunt.verbose.ok(); } catch(e) { // Something went wrong. grunt.verbose.or.write(msg).error().error(e.message); grunt.fail.warn('Something went wrong.'); } }); 解释以上代码: grunt.verbose.write(msg); 只有在 --verbose 模式时才会输出日志信息(没有换行符)。 grunt.verbose.ok(); 以绿色输出日志信息,末尾输出换行符。 grunt.verbose.or.write(msg).error().error(e.message); 做了以下几件事: grunt.verbose.or.write(msg) 如果不在 --verbose 模式则输出日志信息,然后返回notverbose 对象。 .error() 以红色输出ERROR日志,结尾输出换行符,然后返回 notverbose 对象。 .error(e.message); 输出实际的错误信息(并返回 notverbose 对象)。 grunt.fail.warn('Something went wrong.'); 以嫩黄色输出警告信息。除非在命令行指定了--force 选项,否则输出退出码1,然后退出 Grunt。 (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |