在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 物聯(lián)網(wǎng)/ grunt.log
深入任務(wù)內(nèi)幕
grunt.option
退出碼
創(chuàng)建插件
grunt.file
grunt
快速入門(mén)
項(xiàng)目腳手架
使用命令行工具
Gruntfile 實(shí)例
配置任務(wù)
創(chuàng)建任務(wù)
grunt.log
安裝Grunt
grunt.util
grunt.event
常見(jiàn)問(wèn)題
grunt.config
grunt.task
grunt.template
grunt.fail

grunt.log

輸出信息到控制器。

查看log庫(kù)源文件可以了解更多詳細(xì)信息。

The log API

Grunt輸出看起來(lái)應(yīng)該是一致的,甚至是漂亮的。因此,這里有大量的日志記錄相關(guān)的方法和一些很有用的模式。所有的這些方法實(shí)際上記錄的東西的都是可連接的。

注意:所有grunt.verbose下可用的方法都酷似grunt.log方法,不同的是,如果指定--verbose命令行選項(xiàng),那么它就只會(huì)記錄日志信息。

grunt.log.write/grunt.verbose.write

輸出指定的msg字符串信息,尾部不帶換行符。

grunt.log.write(msg);

grunt.log.weiteln/grunt.verbose.writeln

輸出指定的msg字符串信息,尾部帶有換行符。

grunt.log.writeln([msg]);

grunt.log.error/grunt.verbose.error

如果忽略了msg字符串,它會(huì)輸出紅色的ERROR信息;否則輸出>> msg并且尾部帶有換行符。

grunt.log.error([msg])

grunt.log.errorlns/grunt.verbose.errorlns

使用grunt.log.error會(huì)輸出一個(gè)錯(cuò)誤日志信息,使用grunt.log.wraptext可以做到每80個(gè)文本就換行(即保證輸出最大列數(shù)為80列)。

grunt.log/errorlns(msg)

grunt.log.ok/grunt.verbose.ok

如果忽略msg字符串,它會(huì)輸出綠色的OK信息;否則輸出>> msg并且尾部帶有換行符。

grunt.log.ok([msg])

grunt.log.oklns/grunt.verbose.oklns

使用grunt.log.ok方法輸出一個(gè)ok信息,使用grunt.log.wraptext可以做到每80個(gè)文本就換行。

grunt.log.oklns(msg)

grunt.log.subhead/grunt.verbose.subhead

以加粗的形式輸出指定的msg字符串,尾部帶有換行符。

grunt.log.subhead(msg)

grunt.log.writeflags/grunt.verbose.writeflags

輸出一個(gè)obj屬性列表(它是很好的調(diào)試標(biāo)志)。

grunt.log.writeflags(obj, prefix)

grunt.log.debug/grunt.verbose.debug

輸出一個(gè)調(diào)試信息,但是只在指定--debug命令行選項(xiàng)的情況下才會(huì)輸出。

grunt.log.debug(msg)

Verbose and Notverbose

所有grunt.verbose下可用的日志記錄方法的工作都酷似它們所對(duì)應(yīng)的grunt.log方法,但是它們只在指定--verbose命令行選項(xiàng)的情況下才一樣。還有一個(gè)對(duì)應(yīng)"notverbose"適用于grunt.log.notverbosegrunt.log.verbose.or。實(shí)際上,.or屬性也可以用于在verbosenotverbose兩者之間有效的進(jìn)行切換。

grunt.verbose/grunt.log.verbose

這個(gè)對(duì)象包含grunt.log下的所有方法,但是只在指定--verbose命令行選項(xiàng)情況下它才會(huì)輸出日志信息。

grunt.verbose

grunt.verbose.or/grunt.log.notverbose

這個(gè)對(duì)象也包含grunt.log下的所有方法,但是只在不指定--verbose命令行選項(xiàng)情況下它才會(huì)輸出日志信息。

grunt.verbose.or

工具方法

這些方法不會(huì)真正輸出日志信息,它們只返回可以用于其他方法中的字符串。

grunt.log.wordlist

返回一個(gè)逗號(hào)分割的arr數(shù)組項(xiàng)目。

grunt.log.wordlist(arr [, options])

options對(duì)象可以使用以下屬性,并且還可以設(shè)置它們默認(rèn)值:

var options = {
    // The separator string (can be colored).
    separator: ', ',
    // The array item color (specify false to not colorize).
    color: 'cyan',
};

grunt.log.uncolor

從字符串中移除所有的彩色信息,使它適用于測(cè)試.length屬性或者可以輸出到一個(gè)日志記錄文件中。

grunt.log.uncolor(str)

grunt.log.wraptext

text字符串包裝為width指定寬度字符列并在尾部添加一個(gè)\n(換行符),確保單詞沒(méi)有從中間分割,除非絕對(duì)必要的情況下才可以使用分割的單詞。

grunt.log.wraptext(width, text)

grunt.log.table

texts字符串?dāng)?shù)組包裝為widths指定寬度的字符串列數(shù)。包裝函數(shù)grunt.log.wraptext方法可以用于生成輸出列。

grunt.log.table(widths, texts)

示例

一個(gè)常見(jiàn)的模式,發(fā)生錯(cuò)誤時(shí),它只在指定--verbose mode OR選項(xiàng)的情況下輸出日志信息。就像下面這樣:

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.');
    }
});

關(guān)于以上代碼的說(shuō)明:

  1. grunt.verbose.write(msg) 輸出指定的信息(沒(méi)有換行符),但是只在指定--verbose選項(xiàng)的模式下才能正常工作;
  2. grunt.verbose.ok() 輸出綠色的OK信息,尾部帶有換行符;
  3. grunt.verbose.or.write(msg).error().error(e.message)做了好幾件事情:
    1. 如果不在指定--verbose選項(xiàng)的模式下則grunt.verbose.or.write(msg)輸出信息(沒(méi)有換行符),并且它會(huì)返回`norverbos對(duì)象;
    2. .error() 輸出紅色的ERROR信息,尾部帶有換行符,它也會(huì)返回notverbose對(duì)象;
    3. .error(e.message); 輸出實(shí)際的錯(cuò)誤信息(同時(shí)返回notverbose對(duì)象);
  4. grunt.fail.warn('Something went wrong.'); 輸出一個(gè)淺黃色的警告信息,可以使用出口代碼1退出Grunt,除非指定了--force選項(xiàng)。

查看grunt-contrib-*任務(wù)源碼可以看到更多的例子。

上一篇:grunt下一篇:grunt.option