{"id":2609,"date":"2018-04-05T16:37:54","date_gmt":"2018-04-05T08:37:54","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=2609"},"modified":"2018-04-05T16:37:54","modified_gmt":"2018-04-05T08:37:54","slug":"consola-%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=2609","title":{"rendered":"consola \u6559\u7a0b"},"content":{"rendered":"<p>\n\t\u4f60\u6ca1\u770b\u9519\uff0cconsola \u548c&nbsp;console \u53ea\u5dee\u4e00\u4e2a\u5b57\u6bcd\uff0c\u5e76\u4e14\u5b83\u4eec\u90fd\u662f\u63a7\u5236\u5668\u65e5\u5fd7\u8f93\u51fa\u7684\u597d\u5e2e\u624b\u3002console \u5728\u67d0\u4e9b\u65b9\u9762\uff0c\u4f7f\u7528\u6709\u4e9b\u5c40\u9650\u6027\u3002consola \u662f\u4e00\u4e2a\u529f\u80fd\u66f4\u4e30\u5bcc\uff0c\u66f4\u6f02\u4eae\u7684\u63a7\u5236\u53f0\u65e5\u5fd7\u8f93\u51fa\u63a7\u4ef6\u3002\u4eca\u5929\u6211\u4eec\u4e00\u8d77\u6765\u5b66\u4e60\u5b83\u7684\u4e00\u4e9b\u7528\u6cd5\u3002\n<\/p>\n<h2>\n\t\u4ec0\u4e48\u662f&nbsp;Consola \uff1f<br \/>\n<\/h2>\n<ul>\n<li>\n\t\tEasy to use \u6613\u4e8e\u4f7f\u7528\u3002\n\t<\/li>\n<li>\n\t\tFancy output with Fallback for Continuous Integration (CI) environments&nbsp;\u5177\u6709\u8fde\u7eed\u96c6\u6210\uff08CI\uff09\u73af\u5883\u7684\u5907\u7528\u8f93\u51fa\u3002\n\t<\/li>\n<li>\n\t\tGlobal mockable stdout\/stderr wrapper&nbsp;\u5168\u7403mockable stdout\/stderr\u5305\u88c5\u3002\n\t<\/li>\n<li>\n\t\tPluggable reporters&nbsp;&nbsp;\u53ef\u63d2\u62d4\u7684\u63d2\u4ef6\u3002\n\t<\/li>\n<li>\n\t\tConsistent Command Line Interface (CLI) experience&nbsp;\u547d\u4ee4\u884c\u63a5\u53e3\uff08CLI\uff09\u3002\n\t<\/li>\n<li>\n\t\tScoped Loggers \u6709\u8303\u56f4\u7684\u8bb0\u5f55\u65e5\u5fd7\u3002\n\t<\/li>\n<\/ul>\n<h2>\n\t\u5b89\u88c5&nbsp;Consola<br \/>\n<\/h2>\n<p>\n\tyarn \u5b89\u88c5\u65b9\u6cd5\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\nyarn add consola<\/pre>\n<p>\n\tnpm \u547d\u4ee4\u5b89\u88c5\u65b9\u6cd5\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\nnpm i consola<\/pre>\n<h2>\n\t\u57fa\u672c\u7528\u6cd5<br \/>\n<\/h2>\n<pre class=\"brush:jscript;\">\r\nconst consola = require(&#039;consola&#039;)\r\n\/\/ \u4e1a\u4f59\u8349\uff1awww.xttblog.com\r\n\/\/ See types section for all available types\r\nconsola.start(&#039;Starting build&#039;)\r\nconsola.success(&#039;Built!&#039;)\r\nconsola.info(&#039;Reporter: Some info&#039;)\r\nconsola.error(new Error(&#039;Foo&#039;))<\/pre>\n<p>\n\t\u56fe\u7247\u6548\u679c\u5982\u4e0b\uff1a\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Consola\" src=\"https:\/\/github.com\/nuxt\/consola\/raw\/master\/assets\/screen1.png\" \/>\n<\/p>\n<p>\n\t\u8f93\u51fa\u7684\u65e5\u5fd7\u5185\u5bb9\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:plain;\">\r\n[2:17:17 PM] Starting build\r\n[2:17:17 PM] [TEST] Log from test scope\r\n[2:17:18 PM] Built!\r\n[2:17:18 PM] Some info\r\n[2:17:18 PM] Error: Foo<\/pre>\n<h2>\n\t\u65e5\u5fd7\u7684\u4f5c\u7528\u57df<br \/>\n<\/h2>\n<p>\n\t\u65e5\u5fd7\u7684\u5206\u7ec4\u4f7f\u7528\uff1a\n<\/p>\n<pre class=\"brush:jscript;\">\r\nconst logger = consola.withScope(&#039;test&#039;)\r\nlogger.info(&#039;Log from test scope&#039;) \/\/ [Test] Log from test scope<\/pre>\n<h2>\n\tReporter<br \/>\n<\/h2>\n<p>\n\t\u6839\u636e\u4e0d\u540c\u7684\u7ec8\u7aef\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f7f\u7528FancyReporter\u6216BasicReporter\u3002\n<\/p>\n<ul>\n<li>\n\t\tBasicReporter\n\t<\/li>\n<li>\n\t\tFancyReporter\n\t<\/li>\n<li>\n\t\tJSONReporter\n\t<\/li>\n<li>\n\t\tWinstonReporter\n\t<\/li>\n<\/ul>\n<p>\n\t\u4e0a\u97624\u4e2a\u662f Consola \u63d0\u4f9b\u76844\u79cd\u53ef\u4f9b\u9009\u62e9\u7684&nbsp;Reporter\u3002\u53e6\u5916\u6211\u4eec\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49 Reporter\u3002\u76f8\u5173\u7528\u6cd5\u53ef\u4ee5\u67e5\u770b\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/github.com\/nuxt\/consola\" name=\"consola\" target=\"_blank\" title=\"consola\">https:\/\/github.com\/nuxt\/consola<\/a>\u3002\u66f4\u591a API \u7684\u7528\u6cd5\u4e5f\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9 demo \u548c\u6587\u6863\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=2609\">consola \u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u4f60\u6ca1\u770b\u9519\uff0cconsola \u548c&nbsp;console \u53ea\u5dee\u4e00\u4e2a\u5b57\u6bcd\uff0c\u5e76\u4e14\u5b83\u4eec\u90fd\u662f\u63a7\u5236\u5668\u65e5\u5fd7\u8f93\u51fa\u7684\u597d\u5e2e\u624b\u3002co [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[1514,900,1106,1433,1493],"class_list":["post-2609","post","type-post","status-publish","format-standard","hentry","category-html5","tag-cnpm","tag-fileinput-js","tag-javascript","tag-npm","tag-webassembly"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2609"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2609\/revisions"}],"predecessor-version":[{"id":2610,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/2609\/revisions\/2610"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}