logger.ts.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>Code coverage report for logger.ts</title>
  5. <meta charset="utf-8" />
  6. <link rel="stylesheet" href="prettify.css" />
  7. <link rel="stylesheet" href="base.css" />
  8. <link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1" />
  10. <style type='text/css'>
  11. .coverage-summary .sorter {
  12. background-image: url(sort-arrow-sprite.png);
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div class='wrapper'>
  18. <div class='pad1'>
  19. <h1><a href="index.html">All files</a> logger.ts</h1>
  20. <div class='clearfix'>
  21. <div class='fl pad1y space-right2'>
  22. <span class="strong">100% </span>
  23. <span class="quiet">Statements</span>
  24. <span class='fraction'>26/26</span>
  25. </div>
  26. <div class='fl pad1y space-right2'>
  27. <span class="strong">78.57% </span>
  28. <span class="quiet">Branches</span>
  29. <span class='fraction'>11/14</span>
  30. </div>
  31. <div class='fl pad1y space-right2'>
  32. <span class="strong">92.86% </span>
  33. <span class="quiet">Functions</span>
  34. <span class='fraction'>13/14</span>
  35. </div>
  36. <div class='fl pad1y space-right2'>
  37. <span class="strong">100% </span>
  38. <span class="quiet">Lines</span>
  39. <span class='fraction'>26/26</span>
  40. </div>
  41. </div>
  42. <p class="quiet">
  43. Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
  44. </p>
  45. <template id="filterTemplate">
  46. <div class="quiet">
  47. Filter:
  48. <input oninput="onInput()" type="search" id="fileSearch">
  49. </div>
  50. </template>
  51. </div>
  52. <div class='status-line high'></div>
  53. <pre><table class="coverage">
  54. <tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
  55. <a name='L2'></a><a href='#L2'>2</a>
  56. <a name='L3'></a><a href='#L3'>3</a>
  57. <a name='L4'></a><a href='#L4'>4</a>
  58. <a name='L5'></a><a href='#L5'>5</a>
  59. <a name='L6'></a><a href='#L6'>6</a>
  60. <a name='L7'></a><a href='#L7'>7</a>
  61. <a name='L8'></a><a href='#L8'>8</a>
  62. <a name='L9'></a><a href='#L9'>9</a>
  63. <a name='L10'></a><a href='#L10'>10</a>
  64. <a name='L11'></a><a href='#L11'>11</a>
  65. <a name='L12'></a><a href='#L12'>12</a>
  66. <a name='L13'></a><a href='#L13'>13</a>
  67. <a name='L14'></a><a href='#L14'>14</a>
  68. <a name='L15'></a><a href='#L15'>15</a>
  69. <a name='L16'></a><a href='#L16'>16</a>
  70. <a name='L17'></a><a href='#L17'>17</a>
  71. <a name='L18'></a><a href='#L18'>18</a>
  72. <a name='L19'></a><a href='#L19'>19</a>
  73. <a name='L20'></a><a href='#L20'>20</a>
  74. <a name='L21'></a><a href='#L21'>21</a>
  75. <a name='L22'></a><a href='#L22'>22</a>
  76. <a name='L23'></a><a href='#L23'>23</a>
  77. <a name='L24'></a><a href='#L24'>24</a>
  78. <a name='L25'></a><a href='#L25'>25</a>
  79. <a name='L26'></a><a href='#L26'>26</a>
  80. <a name='L27'></a><a href='#L27'>27</a>
  81. <a name='L28'></a><a href='#L28'>28</a>
  82. <a name='L29'></a><a href='#L29'>29</a>
  83. <a name='L30'></a><a href='#L30'>30</a>
  84. <a name='L31'></a><a href='#L31'>31</a>
  85. <a name='L32'></a><a href='#L32'>32</a>
  86. <a name='L33'></a><a href='#L33'>33</a>
  87. <a name='L34'></a><a href='#L34'>34</a>
  88. <a name='L35'></a><a href='#L35'>35</a>
  89. <a name='L36'></a><a href='#L36'>36</a>
  90. <a name='L37'></a><a href='#L37'>37</a>
  91. <a name='L38'></a><a href='#L38'>38</a>
  92. <a name='L39'></a><a href='#L39'>39</a>
  93. <a name='L40'></a><a href='#L40'>40</a>
  94. <a name='L41'></a><a href='#L41'>41</a>
  95. <a name='L42'></a><a href='#L42'>42</a>
  96. <a name='L43'></a><a href='#L43'>43</a>
  97. <a name='L44'></a><a href='#L44'>44</a>
  98. <a name='L45'></a><a href='#L45'>45</a>
  99. <a name='L46'></a><a href='#L46'>46</a>
  100. <a name='L47'></a><a href='#L47'>47</a>
  101. <a name='L48'></a><a href='#L48'>48</a>
  102. <a name='L49'></a><a href='#L49'>49</a>
  103. <a name='L50'></a><a href='#L50'>50</a>
  104. <a name='L51'></a><a href='#L51'>51</a>
  105. <a name='L52'></a><a href='#L52'>52</a>
  106. <a name='L53'></a><a href='#L53'>53</a>
  107. <a name='L54'></a><a href='#L54'>54</a>
  108. <a name='L55'></a><a href='#L55'>55</a>
  109. <a name='L56'></a><a href='#L56'>56</a>
  110. <a name='L57'></a><a href='#L57'>57</a>
  111. <a name='L58'></a><a href='#L58'>58</a>
  112. <a name='L59'></a><a href='#L59'>59</a>
  113. <a name='L60'></a><a href='#L60'>60</a>
  114. <a name='L61'></a><a href='#L61'>61</a>
  115. <a name='L62'></a><a href='#L62'>62</a>
  116. <a name='L63'></a><a href='#L63'>63</a>
  117. <a name='L64'></a><a href='#L64'>64</a>
  118. <a name='L65'></a><a href='#L65'>65</a>
  119. <a name='L66'></a><a href='#L66'>66</a>
  120. <a name='L67'></a><a href='#L67'>67</a>
  121. <a name='L68'></a><a href='#L68'>68</a>
  122. <a name='L69'></a><a href='#L69'>69</a>
  123. <a name='L70'></a><a href='#L70'>70</a>
  124. <a name='L71'></a><a href='#L71'>71</a>
  125. <a name='L72'></a><a href='#L72'>72</a>
  126. <a name='L73'></a><a href='#L73'>73</a>
  127. <a name='L74'></a><a href='#L74'>74</a>
  128. <a name='L75'></a><a href='#L75'>75</a>
  129. <a name='L76'></a><a href='#L76'>76</a>
  130. <a name='L77'></a><a href='#L77'>77</a>
  131. <a name='L78'></a><a href='#L78'>78</a>
  132. <a name='L79'></a><a href='#L79'>79</a>
  133. <a name='L80'></a><a href='#L80'>80</a>
  134. <a name='L81'></a><a href='#L81'>81</a>
  135. <a name='L82'></a><a href='#L82'>82</a>
  136. <a name='L83'></a><a href='#L83'>83</a>
  137. <a name='L84'></a><a href='#L84'>84</a>
  138. <a name='L85'></a><a href='#L85'>85</a>
  139. <a name='L86'></a><a href='#L86'>86</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">2x</span>
  140. <span class="cline-any cline-neutral">&nbsp;</span>
  141. <span class="cline-any cline-neutral">&nbsp;</span>
  142. <span class="cline-any cline-neutral">&nbsp;</span>
  143. <span class="cline-any cline-neutral">&nbsp;</span>
  144. <span class="cline-any cline-neutral">&nbsp;</span>
  145. <span class="cline-any cline-neutral">&nbsp;</span>
  146. <span class="cline-any cline-neutral">&nbsp;</span>
  147. <span class="cline-any cline-neutral">&nbsp;</span>
  148. <span class="cline-any cline-neutral">&nbsp;</span>
  149. <span class="cline-any cline-neutral">&nbsp;</span>
  150. <span class="cline-any cline-neutral">&nbsp;</span>
  151. <span class="cline-any cline-neutral">&nbsp;</span>
  152. <span class="cline-any cline-neutral">&nbsp;</span>
  153. <span class="cline-any cline-neutral">&nbsp;</span>
  154. <span class="cline-any cline-neutral">&nbsp;</span>
  155. <span class="cline-any cline-yes">2x</span>
  156. <span class="cline-any cline-yes">2x</span>
  157. <span class="cline-any cline-yes">2x</span>
  158. <span class="cline-any cline-yes">2x</span>
  159. <span class="cline-any cline-neutral">&nbsp;</span>
  160. <span class="cline-any cline-neutral">&nbsp;</span>
  161. <span class="cline-any cline-yes">2x</span>
  162. <span class="cline-any cline-yes">2x</span>
  163. <span class="cline-any cline-neutral">&nbsp;</span>
  164. <span class="cline-any cline-yes">2x</span>
  165. <span class="cline-any cline-neutral">&nbsp;</span>
  166. <span class="cline-any cline-neutral">&nbsp;</span>
  167. <span class="cline-any cline-neutral">&nbsp;</span>
  168. <span class="cline-any cline-yes">2x</span>
  169. <span class="cline-any cline-yes">5x</span>
  170. <span class="cline-any cline-neutral">&nbsp;</span>
  171. <span class="cline-any cline-neutral">&nbsp;</span>
  172. <span class="cline-any cline-neutral">&nbsp;</span>
  173. <span class="cline-any cline-yes">8x</span>
  174. <span class="cline-any cline-neutral">&nbsp;</span>
  175. <span class="cline-any cline-yes">2x</span>
  176. <span class="cline-any cline-neutral">&nbsp;</span>
  177. <span class="cline-any cline-neutral">&nbsp;</span>
  178. <span class="cline-any cline-yes">5x</span>
  179. <span class="cline-any cline-yes">2x</span>
  180. <span class="cline-any cline-neutral">&nbsp;</span>
  181. <span class="cline-any cline-neutral">&nbsp;</span>
  182. <span class="cline-any cline-neutral">&nbsp;</span>
  183. <span class="cline-any cline-neutral">&nbsp;</span>
  184. <span class="cline-any cline-yes">2x</span>
  185. <span class="cline-any cline-neutral">&nbsp;</span>
  186. <span class="cline-any cline-neutral">&nbsp;</span>
  187. <span class="cline-any cline-neutral">&nbsp;</span>
  188. <span class="cline-any cline-neutral">&nbsp;</span>
  189. <span class="cline-any cline-yes">5x</span>
  190. <span class="cline-any cline-neutral">&nbsp;</span>
  191. <span class="cline-any cline-yes">4x</span>
  192. <span class="cline-any cline-neutral">&nbsp;</span>
  193. <span class="cline-any cline-neutral">&nbsp;</span>
  194. <span class="cline-any cline-neutral">&nbsp;</span>
  195. <span class="cline-any cline-neutral">&nbsp;</span>
  196. <span class="cline-any cline-neutral">&nbsp;</span>
  197. <span class="cline-any cline-yes">2x</span>
  198. <span class="cline-any cline-neutral">&nbsp;</span>
  199. <span class="cline-any cline-neutral">&nbsp;</span>
  200. <span class="cline-any cline-neutral">&nbsp;</span>
  201. <span class="cline-any cline-neutral">&nbsp;</span>
  202. <span class="cline-any cline-yes">5x</span>
  203. <span class="cline-any cline-yes">1x</span>
  204. <span class="cline-any cline-neutral">&nbsp;</span>
  205. <span class="cline-any cline-neutral">&nbsp;</span>
  206. <span class="cline-any cline-yes">2x</span>
  207. <span class="cline-any cline-neutral">&nbsp;</span>
  208. <span class="cline-any cline-neutral">&nbsp;</span>
  209. <span class="cline-any cline-neutral">&nbsp;</span>
  210. <span class="cline-any cline-neutral">&nbsp;</span>
  211. <span class="cline-any cline-yes">5x</span>
  212. <span class="cline-any cline-yes">1x</span>
  213. <span class="cline-any cline-neutral">&nbsp;</span>
  214. <span class="cline-any cline-neutral">&nbsp;</span>
  215. <span class="cline-any cline-yes">2x</span>
  216. <span class="cline-any cline-yes">5x</span>
  217. <span class="cline-any cline-yes">5x</span>
  218. <span class="cline-any cline-neutral">&nbsp;</span>
  219. <span class="cline-any cline-neutral">&nbsp;</span>
  220. <span class="cline-any cline-neutral">&nbsp;</span>
  221. <span class="cline-any cline-neutral">&nbsp;</span>
  222. <span class="cline-any cline-neutral">&nbsp;</span>
  223. <span class="cline-any cline-neutral">&nbsp;</span>
  224. <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import { Console } from "console";
  225. import { Options } from "./options";
  226. import { Chalk } from "chalk";
  227. &nbsp;
  228. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  229. type InternalLoggerFunc = (whereToLog: any, message: string) =&gt; void;
  230. &nbsp;
  231. export type LoggerFunc = (message: string) =&gt; void;
  232. &nbsp;
  233. export interface Logger {
  234. log: LoggerFunc;
  235. logInfo: LoggerFunc;
  236. logWarning: LoggerFunc;
  237. logError: LoggerFunc;
  238. }
  239. &nbsp;
  240. enum LogLevel {
  241. INFO = 1,
  242. WARN = 2,
  243. ERROR = 3,
  244. }
  245. &nbsp;
  246. const stderrConsole = new Console(process.stderr);
  247. const stdoutConsole = new Console(process.stdout);
  248. &nbsp;
  249. const doNothingLogger = (_message: string): void =&gt; {
  250. /* Do nothing */
  251. };
  252. &nbsp;
  253. const makeLoggerFunc = (options: Options): InternalLoggerFunc =&gt;
  254. options.silent
  255. ? <span class="fstat-no" title="function not covered" ><span class="branch-0 cbranch-no" title="branch not covered" >(_</span>whereToLog: Console, _message: string) =&gt; {</span>
  256. /* Do nothing */
  257. }
  258. : (whereToLog: Console, message: string) =&gt; whereToLog.log(message);
  259. &nbsp;
  260. const makeExternalLogger = (
  261. loaderOptions: Options,
  262. logger: InternalLoggerFunc
  263. ): LoggerFunc =&gt; (message: string) =&gt;
  264. logger(
  265. loaderOptions.logInfoToStdOut ? stdoutConsole : stderrConsole,
  266. message
  267. );
  268. &nbsp;
  269. const makeLogInfo = (
  270. options: Options,
  271. logger: InternalLoggerFunc,
  272. green: Chalk
  273. ): LoggerFunc =&gt;
  274. LogLevel[options.logLevel] &lt;= LogLevel.INFO
  275. ? (message: string) =&gt;
  276. logger(
  277. options.logInfoToStdOut ? stdoutConsole : stderrConsole,
  278. green(message)
  279. )
  280. : doNothingLogger;
  281. &nbsp;
  282. const makeLogError = (
  283. options: Options,
  284. logger: InternalLoggerFunc,
  285. red: Chalk
  286. ): LoggerFunc =&gt;
  287. LogLevel[options.logLevel] &lt;= LogLevel.ERROR
  288. ? (message: string) =&gt; logger(stderrConsole, red(message))
  289. : <span class="branch-1 cbranch-no" title="branch not covered" >doNothingLogger;</span>
  290. &nbsp;
  291. const makeLogWarning = (
  292. options: Options,
  293. logger: InternalLoggerFunc,
  294. yellow: Chalk
  295. ): LoggerFunc =&gt;
  296. LogLevel[options.logLevel] &lt;= LogLevel.WARN
  297. ? (message: string) =&gt; logger(stderrConsole, yellow(message))
  298. : <span class="branch-1 cbranch-no" title="branch not covered" >doNothingLogger;</span>
  299. &nbsp;
  300. export function makeLogger(options: Options, colors: Chalk): Logger {
  301. const logger = makeLoggerFunc(options);
  302. return {
  303. log: makeExternalLogger(options, logger),
  304. logInfo: makeLogInfo(options, logger, colors.green),
  305. logWarning: makeLogWarning(options, logger, colors.yellow),
  306. logError: makeLogError(options, logger, colors.red),
  307. };
  308. }
  309. &nbsp;</pre></td></tr></table></pre>
  310. <div class='push'></div><!-- for sticky footer -->
  311. </div><!-- /wrapper -->
  312. <div class='footer quiet pad2 space-top1 center small'>
  313. Code coverage generated by
  314. <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
  315. at 2023-07-11T18:47:03.190Z
  316. </div>
  317. <script src="prettify.js"></script>
  318. <script>
  319. window.onload = function () {
  320. prettyPrint();
  321. };
  322. </script>
  323. <script src="sorter.js"></script>
  324. <script src="block-navigation.js"></script>
  325. </body>
  326. </html>