standard-log 8.0.1 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (613) hide show
  1. package/README.md +57 -133
  2. package/{esm/console/createConsoleLogReporter.d.ts → cjs/console.d.ts} +5 -5
  3. package/cjs/console.d.ts.map +1 -0
  4. package/cjs/console.js +76 -0
  5. package/cjs/console.js.map +1 -0
  6. package/cjs/console.spec.d.ts +2 -0
  7. package/cjs/console.spec.d.ts.map +1 -0
  8. package/cjs/{console/createConsoleLogReporter.spec.js → console.spec.js} +50 -68
  9. package/cjs/console.spec.js.map +1 -0
  10. package/cjs/errors.d.ts +0 -10
  11. package/cjs/errors.d.ts.map +1 -1
  12. package/cjs/errors.js +1 -43
  13. package/cjs/errors.js.map +1 -1
  14. package/cjs/formatter.d.ts +6 -0
  15. package/cjs/formatter.d.ts.map +1 -0
  16. package/cjs/formatter.js +46 -0
  17. package/cjs/formatter.js.map +1 -0
  18. package/cjs/formatter.spec.d.ts +2 -0
  19. package/cjs/formatter.spec.d.ts.map +1 -0
  20. package/cjs/formatter.spec.js +32 -0
  21. package/cjs/formatter.spec.js.map +1 -0
  22. package/cjs/index.d.ts +5 -14
  23. package/cjs/index.d.ts.map +1 -1
  24. package/cjs/index.js +5 -14
  25. package/cjs/index.js.map +1 -1
  26. package/cjs/logLevels.d.ts +60 -0
  27. package/cjs/logLevels.d.ts.map +1 -0
  28. package/cjs/logLevels.js +87 -0
  29. package/cjs/logLevels.js.map +1 -0
  30. package/cjs/logStore.d.ts +20 -0
  31. package/cjs/logStore.d.ts.map +1 -0
  32. package/cjs/logStore.js +44 -0
  33. package/cjs/logStore.js.map +1 -0
  34. package/cjs/logStore.spec.d.ts +2 -0
  35. package/cjs/logStore.spec.d.ts.map +1 -0
  36. package/cjs/logStore.spec.js +93 -0
  37. package/cjs/logStore.spec.js.map +1 -0
  38. package/cjs/logger.d.ts +6 -0
  39. package/cjs/logger.d.ts.map +1 -0
  40. package/cjs/logger.js +97 -0
  41. package/cjs/logger.js.map +1 -0
  42. package/{esm/memory/MemoryLogReporter.d.ts → cjs/memory.d.ts} +2 -2
  43. package/cjs/memory.d.ts.map +1 -0
  44. package/cjs/memory.js +39 -0
  45. package/cjs/memory.js.map +1 -0
  46. package/cjs/memory.spec.d.ts +2 -0
  47. package/cjs/memory.spec.d.ts.map +1 -0
  48. package/cjs/memory.spec.js +115 -0
  49. package/cjs/memory.spec.js.map +1 -0
  50. package/cjs/package.json +1 -3
  51. package/cjs/platform.browser.d.ts +7 -0
  52. package/cjs/platform.browser.d.ts.map +1 -0
  53. package/cjs/platform.browser.js +11 -0
  54. package/cjs/platform.browser.js.map +1 -0
  55. package/cjs/platform.d.ts +8 -0
  56. package/cjs/platform.d.ts.map +1 -0
  57. package/cjs/platform.js +26 -0
  58. package/cjs/platform.js.map +1 -0
  59. package/cjs/platform.spec.d.ts +2 -0
  60. package/cjs/platform.spec.d.ts.map +1 -0
  61. package/cjs/platform.spec.js +22 -0
  62. package/cjs/platform.spec.js.map +1 -0
  63. package/cjs/standardLog.d.ts +21 -0
  64. package/cjs/standardLog.d.ts.map +1 -0
  65. package/cjs/standardLog.js +59 -0
  66. package/cjs/standardLog.js.map +1 -0
  67. package/cjs/standardLog.spec.d.ts +2 -0
  68. package/cjs/standardLog.spec.d.ts.map +1 -0
  69. package/cjs/standardLog.spec.js +536 -0
  70. package/cjs/standardLog.spec.js.map +1 -0
  71. package/cjs/testUtil.d.ts +7 -5
  72. package/cjs/testUtil.d.ts.map +1 -1
  73. package/cjs/testUtil.js +11 -14
  74. package/cjs/testUtil.js.map +1 -1
  75. package/cjs/types.d.ts +33 -24
  76. package/cjs/types.d.ts.map +1 -1
  77. package/cjs/types.js.map +1 -1
  78. package/dist/standard-log.es5.js +324 -1078
  79. package/dist/standard-log.es5.js.gz +0 -0
  80. package/dist/standard-log.es5.js.map +1 -1
  81. package/dist/standard-log.es5.js.map.gz +0 -0
  82. package/dist/standard-log.esm.js +307 -1145
  83. package/dist/standard-log.esm.js.gz +0 -0
  84. package/dist/standard-log.esm.js.map +1 -1
  85. package/dist/standard-log.esm.js.map.gz +0 -0
  86. package/{cjs/console/createConsoleLogReporter.d.ts → esm/console.d.ts} +5 -5
  87. package/esm/console.d.ts.map +1 -0
  88. package/esm/{console/polyfilledConsole.js → console.js} +36 -4
  89. package/esm/console.js.map +1 -0
  90. package/esm/console.spec.d.ts +2 -0
  91. package/esm/console.spec.d.ts.map +1 -0
  92. package/esm/{console/createConsoleLogReporter.spec.js → console.spec.js} +50 -65
  93. package/esm/console.spec.js.map +1 -0
  94. package/esm/errors.d.ts +0 -10
  95. package/esm/errors.d.ts.map +1 -1
  96. package/esm/errors.js +0 -34
  97. package/esm/errors.js.map +1 -1
  98. package/esm/formatter.d.ts +6 -0
  99. package/esm/formatter.d.ts.map +1 -0
  100. package/esm/{formatter/createTimestampFormatter.js → formatter.js} +10 -2
  101. package/esm/formatter.js.map +1 -0
  102. package/esm/formatter.spec.d.ts +2 -0
  103. package/esm/formatter.spec.d.ts.map +1 -0
  104. package/esm/formatter.spec.js +30 -0
  105. package/esm/formatter.spec.js.map +1 -0
  106. package/esm/index.d.ts +5 -14
  107. package/esm/index.d.ts.map +1 -1
  108. package/esm/index.js +5 -14
  109. package/esm/index.js.map +1 -1
  110. package/esm/logLevels.d.ts +60 -0
  111. package/esm/logLevels.d.ts.map +1 -0
  112. package/esm/{logLevel.js → logLevels.js} +29 -3
  113. package/esm/logLevels.js.map +1 -0
  114. package/esm/logStore.d.ts +20 -0
  115. package/esm/logStore.d.ts.map +1 -0
  116. package/esm/logStore.js +37 -0
  117. package/esm/logStore.js.map +1 -0
  118. package/esm/logStore.spec.d.ts +2 -0
  119. package/esm/logStore.spec.d.ts.map +1 -0
  120. package/esm/logStore.spec.js +93 -0
  121. package/esm/logStore.spec.js.map +1 -0
  122. package/esm/logger.d.ts +6 -0
  123. package/esm/logger.d.ts.map +1 -0
  124. package/esm/logger.js +74 -0
  125. package/esm/logger.js.map +1 -0
  126. package/{cjs/memory/MemoryLogReporter.d.ts → esm/memory.d.ts} +2 -2
  127. package/esm/memory.d.ts.map +1 -0
  128. package/esm/memory.js +34 -0
  129. package/esm/memory.js.map +1 -0
  130. package/esm/memory.spec.d.ts +2 -0
  131. package/esm/memory.spec.d.ts.map +1 -0
  132. package/esm/memory.spec.js +110 -0
  133. package/esm/memory.spec.js.map +1 -0
  134. package/esm/platform.browser.d.ts +7 -0
  135. package/esm/platform.browser.d.ts.map +1 -0
  136. package/esm/platform.browser.js +6 -0
  137. package/esm/platform.browser.js.map +1 -0
  138. package/esm/platform.d.ts +8 -0
  139. package/esm/platform.d.ts.map +1 -0
  140. package/esm/platform.js +20 -0
  141. package/esm/platform.js.map +1 -0
  142. package/esm/platform.spec.d.ts +2 -0
  143. package/esm/platform.spec.d.ts.map +1 -0
  144. package/esm/{console/semverGt.spec.js → platform.spec.js} +2 -2
  145. package/esm/platform.spec.js.map +1 -0
  146. package/esm/standardLog.d.ts +21 -0
  147. package/esm/standardLog.d.ts.map +1 -0
  148. package/esm/standardLog.js +36 -0
  149. package/esm/standardLog.js.map +1 -0
  150. package/esm/standardLog.spec.d.ts +2 -0
  151. package/esm/standardLog.spec.d.ts.map +1 -0
  152. package/esm/standardLog.spec.js +434 -0
  153. package/esm/standardLog.spec.js.map +1 -0
  154. package/esm/testUtil.d.ts +7 -5
  155. package/esm/testUtil.d.ts.map +1 -1
  156. package/esm/testUtil.js +8 -12
  157. package/esm/testUtil.js.map +1 -1
  158. package/esm/types.d.ts +33 -24
  159. package/esm/types.d.ts.map +1 -1
  160. package/esm/types.js.map +1 -1
  161. package/package.json +10 -19
  162. package/ts/console.ts +72 -0
  163. package/ts/errors.ts +0 -12
  164. package/ts/{formatter/createTimestampFormatter.ts → formatter.ts} +12 -1
  165. package/ts/index.ts +5 -14
  166. package/ts/{logLevel.ts → logLevels.ts} +20 -3
  167. package/ts/logStore.ts +52 -0
  168. package/ts/logger.ts +85 -0
  169. package/ts/memory.ts +47 -0
  170. package/ts/platform.browser.ts +8 -0
  171. package/ts/platform.ts +25 -0
  172. package/ts/standardLog.ts +54 -0
  173. package/ts/types.ts +39 -30
  174. package/cjs/LogEntry.d.ts +0 -7
  175. package/cjs/LogEntry.d.ts.map +0 -1
  176. package/cjs/LogEntry.js +0 -3
  177. package/cjs/LogEntry.js.map +0 -1
  178. package/cjs/captureLogs.d.ts +0 -4
  179. package/cjs/captureLogs.d.ts.map +0 -1
  180. package/cjs/captureLogs.js +0 -33
  181. package/cjs/captureLogs.js.map +0 -1
  182. package/cjs/captureLogs.spec.d.ts +0 -2
  183. package/cjs/captureLogs.spec.d.ts.map +0 -1
  184. package/cjs/captureLogs.spec.js +0 -117
  185. package/cjs/captureLogs.spec.js.map +0 -1
  186. package/cjs/config.d.ts +0 -12
  187. package/cjs/config.d.ts.map +0 -1
  188. package/cjs/config.js +0 -59
  189. package/cjs/config.js.map +0 -1
  190. package/cjs/config.spec.d.ts +0 -2
  191. package/cjs/config.spec.d.ts.map +0 -1
  192. package/cjs/config.spec.js +0 -72
  193. package/cjs/config.spec.js.map +0 -1
  194. package/cjs/configForTest.d.ts +0 -5
  195. package/cjs/configForTest.d.ts.map +0 -1
  196. package/cjs/configForTest.js +0 -18
  197. package/cjs/configForTest.js.map +0 -1
  198. package/cjs/configForTest.spec.d.ts +0 -2
  199. package/cjs/configForTest.spec.d.ts.map +0 -1
  200. package/cjs/configForTest.spec.js +0 -17
  201. package/cjs/configForTest.spec.js.map +0 -1
  202. package/cjs/console/createConsoleLogReporter.d.ts.map +0 -1
  203. package/cjs/console/createConsoleLogReporter.js +0 -42
  204. package/cjs/console/createConsoleLogReporter.js.map +0 -1
  205. package/cjs/console/createConsoleLogReporter.spec.d.ts +0 -2
  206. package/cjs/console/createConsoleLogReporter.spec.d.ts.map +0 -1
  207. package/cjs/console/createConsoleLogReporter.spec.js.map +0 -1
  208. package/cjs/console/index.d.ts +0 -4
  209. package/cjs/console/index.d.ts.map +0 -1
  210. package/cjs/console/index.js +0 -20
  211. package/cjs/console/index.js.map +0 -1
  212. package/cjs/console/isConsoleDebugAvailable.d.ts +0 -2
  213. package/cjs/console/isConsoleDebugAvailable.d.ts.map +0 -1
  214. package/cjs/console/isConsoleDebugAvailable.js +0 -20
  215. package/cjs/console/isConsoleDebugAvailable.js.map +0 -1
  216. package/cjs/console/polyfilledConsole.d.ts +0 -7
  217. package/cjs/console/polyfilledConsole.d.ts.map +0 -1
  218. package/cjs/console/polyfilledConsole.js +0 -41
  219. package/cjs/console/polyfilledConsole.js.map +0 -1
  220. package/cjs/console/semverGt.d.ts +0 -2
  221. package/cjs/console/semverGt.d.ts.map +0 -1
  222. package/cjs/console/semverGt.js +0 -13
  223. package/cjs/console/semverGt.js.map +0 -1
  224. package/cjs/console/semverGt.spec.d.ts +0 -2
  225. package/cjs/console/semverGt.spec.d.ts.map +0 -1
  226. package/cjs/console/semverGt.spec.js +0 -22
  227. package/cjs/console/semverGt.spec.js.map +0 -1
  228. package/cjs/console/toConsoleMethod.d.ts +0 -2
  229. package/cjs/console/toConsoleMethod.d.ts.map +0 -1
  230. package/cjs/console/toConsoleMethod.js +0 -22
  231. package/cjs/console/toConsoleMethod.js.map +0 -1
  232. package/cjs/console/types.d.ts +0 -3
  233. package/cjs/console/types.d.ts.map +0 -1
  234. package/cjs/console/types.js +0 -3
  235. package/cjs/console/types.js.map +0 -1
  236. package/cjs/customLogLevel.d.ts +0 -11
  237. package/cjs/customLogLevel.d.ts.map +0 -1
  238. package/cjs/customLogLevel.js +0 -38
  239. package/cjs/customLogLevel.js.map +0 -1
  240. package/cjs/customLogLevel.spec.d.ts +0 -2
  241. package/cjs/customLogLevel.spec.d.ts.map +0 -1
  242. package/cjs/customLogLevel.spec.js +0 -37
  243. package/cjs/customLogLevel.spec.js.map +0 -1
  244. package/cjs/formatter/createTimestampFormatter.d.ts +0 -3
  245. package/cjs/formatter/createTimestampFormatter.d.ts.map +0 -1
  246. package/cjs/formatter/createTimestampFormatter.js +0 -26
  247. package/cjs/formatter/createTimestampFormatter.js.map +0 -1
  248. package/cjs/formatter/createTimestampFormatter.spec.d.ts +0 -2
  249. package/cjs/formatter/createTimestampFormatter.spec.d.ts.map +0 -1
  250. package/cjs/formatter/createTimestampFormatter.spec.js +0 -23
  251. package/cjs/formatter/createTimestampFormatter.spec.js.map +0 -1
  252. package/cjs/formatter/formatLogLevel.d.ts +0 -2
  253. package/cjs/formatter/formatLogLevel.d.ts.map +0 -1
  254. package/cjs/formatter/formatLogLevel.js +0 -10
  255. package/cjs/formatter/formatLogLevel.js.map +0 -1
  256. package/cjs/formatter/index.d.ts +0 -4
  257. package/cjs/formatter/index.d.ts.map +0 -1
  258. package/cjs/formatter/index.js +0 -20
  259. package/cjs/formatter/index.js.map +0 -1
  260. package/cjs/formatter/plainLogFormatter.d.ts +0 -3
  261. package/cjs/formatter/plainLogFormatter.d.ts.map +0 -1
  262. package/cjs/formatter/plainLogFormatter.js +0 -19
  263. package/cjs/formatter/plainLogFormatter.js.map +0 -1
  264. package/cjs/formatter/plainLogFormatter.spec.d.ts +0 -2
  265. package/cjs/formatter/plainLogFormatter.spec.d.ts.map +0 -1
  266. package/cjs/formatter/plainLogFormatter.spec.js +0 -9
  267. package/cjs/formatter/plainLogFormatter.spec.js.map +0 -1
  268. package/cjs/getDefaultReporter.browser.d.ts +0 -2
  269. package/cjs/getDefaultReporter.browser.d.ts.map +0 -1
  270. package/cjs/getDefaultReporter.browser.js +0 -15
  271. package/cjs/getDefaultReporter.browser.js.map +0 -1
  272. package/cjs/getDefaultReporter.d.ts +0 -2
  273. package/cjs/getDefaultReporter.d.ts.map +0 -1
  274. package/cjs/getDefaultReporter.js +0 -19
  275. package/cjs/getDefaultReporter.js.map +0 -1
  276. package/cjs/getLogModeFromEnvironment.browser.d.ts +0 -3
  277. package/cjs/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  278. package/cjs/getLogModeFromEnvironment.browser.js +0 -9
  279. package/cjs/getLogModeFromEnvironment.browser.js.map +0 -1
  280. package/cjs/getLogModeFromEnvironment.d.ts +0 -3
  281. package/cjs/getLogModeFromEnvironment.d.ts.map +0 -1
  282. package/cjs/getLogModeFromEnvironment.js +0 -17
  283. package/cjs/getLogModeFromEnvironment.js.map +0 -1
  284. package/cjs/getLogModeFromEnvironment.spec.d.ts +0 -2
  285. package/cjs/getLogModeFromEnvironment.spec.d.ts.map +0 -1
  286. package/cjs/getLogModeFromEnvironment.spec.js +0 -25
  287. package/cjs/getLogModeFromEnvironment.spec.js.map +0 -1
  288. package/cjs/getLogger.d.ts +0 -9
  289. package/cjs/getLogger.d.ts.map +0 -1
  290. package/cjs/getLogger.js +0 -103
  291. package/cjs/getLogger.js.map +0 -1
  292. package/cjs/getLogger.spec.d.ts +0 -2
  293. package/cjs/getLogger.spec.d.ts.map +0 -1
  294. package/cjs/getLogger.spec.js +0 -485
  295. package/cjs/getLogger.spec.js.map +0 -1
  296. package/cjs/getLoggers.d.ts +0 -7
  297. package/cjs/getLoggers.d.ts.map +0 -1
  298. package/cjs/getLoggers.js +0 -15
  299. package/cjs/getLoggers.js.map +0 -1
  300. package/cjs/logLevel.d.ts +0 -106
  301. package/cjs/logLevel.d.ts.map +0 -1
  302. package/cjs/logLevel.js +0 -59
  303. package/cjs/logLevel.js.map +0 -1
  304. package/cjs/logLevel.spec.d.ts +0 -2
  305. package/cjs/logLevel.spec.d.ts.map +0 -1
  306. package/cjs/logLevel.spec.js +0 -195
  307. package/cjs/logLevel.spec.js.map +0 -1
  308. package/cjs/logLevelFn.d.ts +0 -20
  309. package/cjs/logLevelFn.d.ts.map +0 -1
  310. package/cjs/logLevelFn.js +0 -76
  311. package/cjs/logLevelFn.js.map +0 -1
  312. package/cjs/logReporter.d.ts +0 -7
  313. package/cjs/logReporter.d.ts.map +0 -1
  314. package/cjs/logReporter.js +0 -29
  315. package/cjs/logReporter.js.map +0 -1
  316. package/cjs/logReporter.spec.d.ts +0 -2
  317. package/cjs/logReporter.spec.d.ts.map +0 -1
  318. package/cjs/logReporter.spec.js +0 -98
  319. package/cjs/logReporter.spec.js.map +0 -1
  320. package/cjs/logReporterInternal.d.ts +0 -3
  321. package/cjs/logReporterInternal.d.ts.map +0 -1
  322. package/cjs/logReporterInternal.js +0 -23
  323. package/cjs/logReporterInternal.js.map +0 -1
  324. package/cjs/memory/MemoryLogReporter.d.ts.map +0 -1
  325. package/cjs/memory/MemoryLogReporter.js +0 -56
  326. package/cjs/memory/MemoryLogReporter.js.map +0 -1
  327. package/cjs/memory/MemoryLogReporter.spec.d.ts +0 -2
  328. package/cjs/memory/MemoryLogReporter.spec.d.ts.map +0 -1
  329. package/cjs/memory/MemoryLogReporter.spec.js +0 -124
  330. package/cjs/memory/MemoryLogReporter.spec.js.map +0 -1
  331. package/cjs/memory/index.d.ts +0 -3
  332. package/cjs/memory/index.d.ts.map +0 -1
  333. package/cjs/memory/index.js +0 -19
  334. package/cjs/memory/index.js.map +0 -1
  335. package/cjs/memory/logEntriesToString.d.ts +0 -3
  336. package/cjs/memory/logEntriesToString.d.ts.map +0 -1
  337. package/cjs/memory/logEntriesToString.js +0 -10
  338. package/cjs/memory/logEntriesToString.js.map +0 -1
  339. package/cjs/memory/logEntriesToString.spec.d.ts +0 -2
  340. package/cjs/memory/logEntriesToString.spec.d.ts.map +0 -1
  341. package/cjs/memory/logEntriesToString.spec.js +0 -36
  342. package/cjs/memory/logEntriesToString.spec.js.map +0 -1
  343. package/cjs/memory/toInspectStringForObject.d.ts +0 -3
  344. package/cjs/memory/toInspectStringForObject.d.ts.map +0 -1
  345. package/cjs/memory/toInspectStringForObject.js +0 -17
  346. package/cjs/memory/toInspectStringForObject.js.map +0 -1
  347. package/cjs/shouldLog.d.ts +0 -8
  348. package/cjs/shouldLog.d.ts.map +0 -1
  349. package/cjs/shouldLog.js +0 -14
  350. package/cjs/shouldLog.js.map +0 -1
  351. package/cjs/store.d.ts +0 -3
  352. package/cjs/store.d.ts.map +0 -1
  353. package/cjs/store.js +0 -27
  354. package/cjs/store.js.map +0 -1
  355. package/cjs/suppressLogs.d.ts +0 -6
  356. package/cjs/suppressLogs.d.ts.map +0 -1
  357. package/cjs/suppressLogs.js +0 -17
  358. package/cjs/suppressLogs.js.map +0 -1
  359. package/cjs/suppressLogs.spec.d.ts +0 -2
  360. package/cjs/suppressLogs.spec.d.ts.map +0 -1
  361. package/cjs/suppressLogs.spec.js +0 -31
  362. package/cjs/suppressLogs.spec.js.map +0 -1
  363. package/cjs/typesInternal.d.ts +0 -20
  364. package/cjs/typesInternal.d.ts.map +0 -1
  365. package/cjs/typesInternal.js +0 -3
  366. package/cjs/typesInternal.js.map +0 -1
  367. package/cjs/utils.d.ts +0 -6
  368. package/cjs/utils.d.ts.map +0 -1
  369. package/cjs/utils.js +0 -15
  370. package/cjs/utils.js.map +0 -1
  371. package/cjs/writeToReporters.d.ts +0 -6
  372. package/cjs/writeToReporters.d.ts.map +0 -1
  373. package/cjs/writeToReporters.js +0 -22
  374. package/cjs/writeToReporters.js.map +0 -1
  375. package/cjs/writeToReporters.spec.d.ts +0 -2
  376. package/cjs/writeToReporters.spec.d.ts.map +0 -1
  377. package/cjs/writeToReporters.spec.js +0 -59
  378. package/cjs/writeToReporters.spec.js.map +0 -1
  379. package/esm/LogEntry.d.ts +0 -7
  380. package/esm/LogEntry.d.ts.map +0 -1
  381. package/esm/LogEntry.js +0 -2
  382. package/esm/LogEntry.js.map +0 -1
  383. package/esm/captureLogs.d.ts +0 -4
  384. package/esm/captureLogs.d.ts.map +0 -1
  385. package/esm/captureLogs.js +0 -29
  386. package/esm/captureLogs.js.map +0 -1
  387. package/esm/captureLogs.spec.d.ts +0 -2
  388. package/esm/captureLogs.spec.d.ts.map +0 -1
  389. package/esm/captureLogs.spec.js +0 -45
  390. package/esm/captureLogs.spec.js.map +0 -1
  391. package/esm/config.d.ts +0 -12
  392. package/esm/config.d.ts.map +0 -1
  393. package/esm/config.js +0 -44
  394. package/esm/config.js.map +0 -1
  395. package/esm/config.spec.d.ts +0 -2
  396. package/esm/config.spec.d.ts.map +0 -1
  397. package/esm/config.spec.js +0 -67
  398. package/esm/config.spec.js.map +0 -1
  399. package/esm/configForTest.d.ts +0 -5
  400. package/esm/configForTest.d.ts.map +0 -1
  401. package/esm/configForTest.js +0 -14
  402. package/esm/configForTest.js.map +0 -1
  403. package/esm/configForTest.spec.d.ts +0 -2
  404. package/esm/configForTest.spec.d.ts.map +0 -1
  405. package/esm/configForTest.spec.js +0 -15
  406. package/esm/configForTest.spec.js.map +0 -1
  407. package/esm/console/createConsoleLogReporter.d.ts.map +0 -1
  408. package/esm/console/createConsoleLogReporter.js +0 -37
  409. package/esm/console/createConsoleLogReporter.js.map +0 -1
  410. package/esm/console/createConsoleLogReporter.spec.d.ts +0 -2
  411. package/esm/console/createConsoleLogReporter.spec.d.ts.map +0 -1
  412. package/esm/console/createConsoleLogReporter.spec.js.map +0 -1
  413. package/esm/console/index.d.ts +0 -4
  414. package/esm/console/index.d.ts.map +0 -1
  415. package/esm/console/index.js +0 -4
  416. package/esm/console/index.js.map +0 -1
  417. package/esm/console/isConsoleDebugAvailable.d.ts +0 -2
  418. package/esm/console/isConsoleDebugAvailable.d.ts.map +0 -1
  419. package/esm/console/isConsoleDebugAvailable.js +0 -13
  420. package/esm/console/isConsoleDebugAvailable.js.map +0 -1
  421. package/esm/console/polyfilledConsole.d.ts +0 -7
  422. package/esm/console/polyfilledConsole.d.ts.map +0 -1
  423. package/esm/console/polyfilledConsole.js.map +0 -1
  424. package/esm/console/semverGt.d.ts +0 -2
  425. package/esm/console/semverGt.d.ts.map +0 -1
  426. package/esm/console/semverGt.js +0 -9
  427. package/esm/console/semverGt.js.map +0 -1
  428. package/esm/console/semverGt.spec.d.ts +0 -2
  429. package/esm/console/semverGt.spec.d.ts.map +0 -1
  430. package/esm/console/semverGt.spec.js.map +0 -1
  431. package/esm/console/toConsoleMethod.d.ts +0 -2
  432. package/esm/console/toConsoleMethod.d.ts.map +0 -1
  433. package/esm/console/toConsoleMethod.js +0 -18
  434. package/esm/console/toConsoleMethod.js.map +0 -1
  435. package/esm/console/types.d.ts +0 -3
  436. package/esm/console/types.d.ts.map +0 -1
  437. package/esm/console/types.js +0 -2
  438. package/esm/console/types.js.map +0 -1
  439. package/esm/customLogLevel.d.ts +0 -11
  440. package/esm/customLogLevel.d.ts.map +0 -1
  441. package/esm/customLogLevel.js +0 -30
  442. package/esm/customLogLevel.js.map +0 -1
  443. package/esm/customLogLevel.spec.d.ts +0 -2
  444. package/esm/customLogLevel.spec.d.ts.map +0 -1
  445. package/esm/customLogLevel.spec.js +0 -32
  446. package/esm/customLogLevel.spec.js.map +0 -1
  447. package/esm/formatter/createTimestampFormatter.d.ts +0 -3
  448. package/esm/formatter/createTimestampFormatter.d.ts.map +0 -1
  449. package/esm/formatter/createTimestampFormatter.js.map +0 -1
  450. package/esm/formatter/createTimestampFormatter.spec.d.ts +0 -2
  451. package/esm/formatter/createTimestampFormatter.spec.d.ts.map +0 -1
  452. package/esm/formatter/createTimestampFormatter.spec.js +0 -21
  453. package/esm/formatter/createTimestampFormatter.spec.js.map +0 -1
  454. package/esm/formatter/formatLogLevel.d.ts +0 -2
  455. package/esm/formatter/formatLogLevel.d.ts.map +0 -1
  456. package/esm/formatter/formatLogLevel.js +0 -6
  457. package/esm/formatter/formatLogLevel.js.map +0 -1
  458. package/esm/formatter/index.d.ts +0 -4
  459. package/esm/formatter/index.d.ts.map +0 -1
  460. package/esm/formatter/index.js +0 -4
  461. package/esm/formatter/index.js.map +0 -1
  462. package/esm/formatter/plainLogFormatter.d.ts +0 -3
  463. package/esm/formatter/plainLogFormatter.d.ts.map +0 -1
  464. package/esm/formatter/plainLogFormatter.js +0 -5
  465. package/esm/formatter/plainLogFormatter.js.map +0 -1
  466. package/esm/formatter/plainLogFormatter.spec.d.ts +0 -2
  467. package/esm/formatter/plainLogFormatter.spec.d.ts.map +0 -1
  468. package/esm/formatter/plainLogFormatter.spec.js +0 -7
  469. package/esm/formatter/plainLogFormatter.spec.js.map +0 -1
  470. package/esm/getDefaultReporter.browser.d.ts +0 -2
  471. package/esm/getDefaultReporter.browser.d.ts.map +0 -1
  472. package/esm/getDefaultReporter.browser.js +0 -11
  473. package/esm/getDefaultReporter.browser.js.map +0 -1
  474. package/esm/getDefaultReporter.d.ts +0 -2
  475. package/esm/getDefaultReporter.d.ts.map +0 -1
  476. package/esm/getDefaultReporter.js +0 -15
  477. package/esm/getDefaultReporter.js.map +0 -1
  478. package/esm/getLogModeFromEnvironment.browser.d.ts +0 -3
  479. package/esm/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  480. package/esm/getLogModeFromEnvironment.browser.js +0 -5
  481. package/esm/getLogModeFromEnvironment.browser.js.map +0 -1
  482. package/esm/getLogModeFromEnvironment.d.ts +0 -3
  483. package/esm/getLogModeFromEnvironment.d.ts.map +0 -1
  484. package/esm/getLogModeFromEnvironment.js +0 -13
  485. package/esm/getLogModeFromEnvironment.js.map +0 -1
  486. package/esm/getLogModeFromEnvironment.spec.d.ts +0 -2
  487. package/esm/getLogModeFromEnvironment.spec.d.ts.map +0 -1
  488. package/esm/getLogModeFromEnvironment.spec.js +0 -20
  489. package/esm/getLogModeFromEnvironment.spec.js.map +0 -1
  490. package/esm/getLogger.d.ts +0 -9
  491. package/esm/getLogger.d.ts.map +0 -1
  492. package/esm/getLogger.js +0 -78
  493. package/esm/getLogger.js.map +0 -1
  494. package/esm/getLogger.spec.d.ts +0 -2
  495. package/esm/getLogger.spec.d.ts.map +0 -1
  496. package/esm/getLogger.spec.js +0 -385
  497. package/esm/getLogger.spec.js.map +0 -1
  498. package/esm/getLoggers.d.ts +0 -7
  499. package/esm/getLoggers.d.ts.map +0 -1
  500. package/esm/getLoggers.js +0 -11
  501. package/esm/getLoggers.js.map +0 -1
  502. package/esm/logLevel.d.ts +0 -106
  503. package/esm/logLevel.d.ts.map +0 -1
  504. package/esm/logLevel.js.map +0 -1
  505. package/esm/logLevel.spec.d.ts +0 -2
  506. package/esm/logLevel.spec.d.ts.map +0 -1
  507. package/esm/logLevel.spec.js +0 -148
  508. package/esm/logLevel.spec.js.map +0 -1
  509. package/esm/logLevelFn.d.ts +0 -20
  510. package/esm/logLevelFn.d.ts.map +0 -1
  511. package/esm/logLevelFn.js +0 -67
  512. package/esm/logLevelFn.js.map +0 -1
  513. package/esm/logReporter.d.ts +0 -7
  514. package/esm/logReporter.d.ts.map +0 -1
  515. package/esm/logReporter.js +0 -21
  516. package/esm/logReporter.js.map +0 -1
  517. package/esm/logReporter.spec.d.ts +0 -2
  518. package/esm/logReporter.spec.d.ts.map +0 -1
  519. package/esm/logReporter.spec.js +0 -93
  520. package/esm/logReporter.spec.js.map +0 -1
  521. package/esm/logReporterInternal.d.ts +0 -3
  522. package/esm/logReporterInternal.d.ts.map +0 -1
  523. package/esm/logReporterInternal.js +0 -19
  524. package/esm/logReporterInternal.js.map +0 -1
  525. package/esm/memory/MemoryLogReporter.d.ts.map +0 -1
  526. package/esm/memory/MemoryLogReporter.js +0 -51
  527. package/esm/memory/MemoryLogReporter.js.map +0 -1
  528. package/esm/memory/MemoryLogReporter.spec.d.ts +0 -2
  529. package/esm/memory/MemoryLogReporter.spec.d.ts.map +0 -1
  530. package/esm/memory/MemoryLogReporter.spec.js +0 -111
  531. package/esm/memory/MemoryLogReporter.spec.js.map +0 -1
  532. package/esm/memory/index.d.ts +0 -3
  533. package/esm/memory/index.d.ts.map +0 -1
  534. package/esm/memory/index.js +0 -3
  535. package/esm/memory/index.js.map +0 -1
  536. package/esm/memory/logEntriesToString.d.ts +0 -3
  537. package/esm/memory/logEntriesToString.d.ts.map +0 -1
  538. package/esm/memory/logEntriesToString.js +0 -6
  539. package/esm/memory/logEntriesToString.js.map +0 -1
  540. package/esm/memory/logEntriesToString.spec.d.ts +0 -2
  541. package/esm/memory/logEntriesToString.spec.d.ts.map +0 -1
  542. package/esm/memory/logEntriesToString.spec.js +0 -42
  543. package/esm/memory/logEntriesToString.spec.js.map +0 -1
  544. package/esm/memory/toInspectStringForObject.d.ts +0 -3
  545. package/esm/memory/toInspectStringForObject.d.ts.map +0 -1
  546. package/esm/memory/toInspectStringForObject.js +0 -11
  547. package/esm/memory/toInspectStringForObject.js.map +0 -1
  548. package/esm/shouldLog.d.ts +0 -8
  549. package/esm/shouldLog.d.ts.map +0 -1
  550. package/esm/shouldLog.js +0 -10
  551. package/esm/shouldLog.js.map +0 -1
  552. package/esm/store.d.ts +0 -3
  553. package/esm/store.d.ts.map +0 -1
  554. package/esm/store.js +0 -24
  555. package/esm/store.js.map +0 -1
  556. package/esm/suppressLogs.d.ts +0 -6
  557. package/esm/suppressLogs.d.ts.map +0 -1
  558. package/esm/suppressLogs.js +0 -9
  559. package/esm/suppressLogs.js.map +0 -1
  560. package/esm/suppressLogs.spec.d.ts +0 -2
  561. package/esm/suppressLogs.spec.d.ts.map +0 -1
  562. package/esm/suppressLogs.spec.js +0 -29
  563. package/esm/suppressLogs.spec.js.map +0 -1
  564. package/esm/typesInternal.d.ts +0 -20
  565. package/esm/typesInternal.d.ts.map +0 -1
  566. package/esm/typesInternal.js +0 -2
  567. package/esm/typesInternal.js.map +0 -1
  568. package/esm/utils.d.ts +0 -6
  569. package/esm/utils.d.ts.map +0 -1
  570. package/esm/utils.js +0 -11
  571. package/esm/utils.js.map +0 -1
  572. package/esm/writeToReporters.d.ts +0 -6
  573. package/esm/writeToReporters.d.ts.map +0 -1
  574. package/esm/writeToReporters.js +0 -18
  575. package/esm/writeToReporters.js.map +0 -1
  576. package/esm/writeToReporters.spec.d.ts +0 -2
  577. package/esm/writeToReporters.spec.d.ts.map +0 -1
  578. package/esm/writeToReporters.spec.js +0 -9
  579. package/esm/writeToReporters.spec.js.map +0 -1
  580. package/ts/LogEntry.ts +0 -7
  581. package/ts/captureLogs.ts +0 -35
  582. package/ts/config.ts +0 -57
  583. package/ts/configForTest.ts +0 -16
  584. package/ts/console/createConsoleLogReporter.ts +0 -48
  585. package/ts/console/index.ts +0 -3
  586. package/ts/console/isConsoleDebugAvailable.ts +0 -11
  587. package/ts/console/polyfilledConsole.ts +0 -34
  588. package/ts/console/semverGt.ts +0 -9
  589. package/ts/console/toConsoleMethod.ts +0 -18
  590. package/ts/console/types.ts +0 -3
  591. package/ts/customLogLevel.ts +0 -35
  592. package/ts/formatter/formatLogLevel.ts +0 -6
  593. package/ts/formatter/index.ts +0 -3
  594. package/ts/formatter/plainLogFormatter.ts +0 -6
  595. package/ts/getDefaultReporter.browser.ts +0 -13
  596. package/ts/getDefaultReporter.ts +0 -15
  597. package/ts/getLogModeFromEnvironment.browser.ts +0 -6
  598. package/ts/getLogModeFromEnvironment.ts +0 -16
  599. package/ts/getLogger.ts +0 -92
  600. package/ts/getLoggers.ts +0 -12
  601. package/ts/logLevelFn.ts +0 -72
  602. package/ts/logReporter.ts +0 -26
  603. package/ts/logReporterInternal.ts +0 -18
  604. package/ts/memory/MemoryLogReporter.ts +0 -72
  605. package/ts/memory/index.ts +0 -2
  606. package/ts/memory/logEntriesToString.ts +0 -7
  607. package/ts/memory/toInspectStringForObject.ts +0 -13
  608. package/ts/shouldLog.ts +0 -11
  609. package/ts/store.ts +0 -25
  610. package/ts/suppressLogs.ts +0 -14
  611. package/ts/typesInternal.ts +0 -21
  612. package/ts/utils.ts +0 -11
  613. package/ts/writeToReporters.ts +0 -20
package/README.md CHANGED
@@ -3,50 +3,61 @@
3
3
  [![NPM version][npm-image]][npm-url]
4
4
  [![NPM downloads][downloads-image]][downloads-url]
5
5
 
6
- [![Github NodeJS][github-nodejs]][github-action-url]
6
+ [![GitHub NodeJS][github-nodejs]][github-action-url]
7
7
  [![Codecov][codecov-image]][codecov-url]
8
- [![Codacy Grade Badge][codacy-grade]][codacy-grade-url]
9
- [![Codacy Coverage Badge][codacy-coverage]][codacy-coverage-url]
10
-
11
- [![Greenkeeper][greenkeeper-image]][greenkeeper-url]
12
8
 
13
9
  [![Visual Studio Code][vscode-image]][vscode-url]
14
- [![Wallaby.js][wallaby-image]][wallaby-url]
15
10
 
16
- `standard-log` is a powerful and extensible logging library.
11
+ [`standard-log`] is a powerful and extensible logging library.
12
+
13
+ ## New in 9.0
14
+
15
+ [`standard-log`] 9.0 is a trimmed down version that focus more on security and support the micro-app paradigm.
16
+
17
+ The key changes are:
18
+
19
+ - No side effects: application calling `createStandardLog()` gets a completely enclosed log system.
20
+ - Immutable: after the log system can be configured when calling `createStandardLog()`.\
21
+ But after that, the system is immutable and cannot be changed.\
22
+
23
+ For the full list of changes, please check the [change log](./CHANGELOG.md).
17
24
 
18
25
  ## Key features
19
26
 
20
- - create multiple loggers for different part of your application.
21
- - provide multiple log levels out of the box.
22
- - add custom log levels.
23
- - global and local log level control.
24
- - send logs to multiple reporters, e.g. console, file, memory, or remote service.
25
- - custom formatting and filtering for each reporter.
26
- - config tempering protection during production
27
+ - Support micro-app with isolated log system.
28
+ - Create multiple loggers for different part of your application.
29
+ - Provide multiple log levels out of the box.
30
+ - Support custom log levels.
31
+ - Three levels of log level controls: log system, logger, and log method.
32
+ - Send logs to multiple reporters, e.g. console, file, memory, or remote service.
33
+ - Custom formatting and filtering for each reporter.
34
+ - Security focus. After the system is created, it cannot be changed.
35
+ - Compliant with the [`just-func`] paradigm.
27
36
 
28
37
  ## Usage
29
38
 
30
- To use `standard-log`, simply create your logger and log away:
39
+ To use [`standard-log`], you first create a new log system.
31
40
 
32
41
  ```ts
33
- import { getLogger } from 'standard-log'
42
+ import { createStandardLog } from 'standard-log'
43
+
44
+ const standardLog = createStandarLog(/* options */)
34
45
 
35
- const log = getLogger('my-app')
46
+ const log = standardLog.getLogger(['my-app'])
36
47
 
37
- log.error('error')
38
- log.warn('warn')
39
- log.info('info')
48
+ log.error('error message')
49
+ log.warn('warn message')
50
+ log.info('info message')
40
51
  // by default debug() will not be printed
41
52
  // because production mode defaults log level to `info`
42
- log.debug('debug')
53
+ log.debug('debug message')
43
54
  ```
44
55
 
45
- ![rendering-example](images/2019-08-08-23-40-05.png)
56
+ ![Rendering example](images/2022-06-10-19-21-48.png)
46
57
 
47
- (above is logged with `standard-log-color` installed)
58
+ (above is logged with `standard-log-color`)
48
59
 
49
- You can configure a logger by doing `getLogger(id, options)`:
60
+ You can configure a logger by doing `getLogger([id, options])`:
50
61
 
51
62
  `options.level: number`:
52
63
 
@@ -56,41 +67,12 @@ Log level of this logger.
56
67
 
57
68
  Only log to specific reporter(s).
58
69
 
59
- ### Mode
60
-
61
- By default, `standard-log` runs in production mode.
62
- You can change it programmatically:
63
-
64
- ```ts
65
- import { config } from 'standard-log'
66
-
67
- config({ mode: 'production' }) // or 'development', 'test'
68
- ```
69
-
70
- or by setting the environment variable `STANDARD_LOG`.
71
-
72
- `production` mode:
73
-
74
- - `config()` can only be called once.
75
- - configuration is protected from tempering.
76
-
77
- `development` mode:
78
-
79
- - a warning is emitted when calling `config()` or log for the first time.
80
-
81
- `test` mode:
82
-
83
- - no warning is emitted
84
-
85
70
  ### Log Level
86
71
 
87
72
  `standard-log` log level defaults to `logLevels.info`.
88
73
  It comes with many log levels out of the box:
89
74
 
90
75
  ```ts
91
- import { getLogger } from 'standard-log'
92
-
93
- const log = getLogger('x')
94
76
  log.emergency('msg')
95
77
  log.alert('msg')
96
78
  log.critical('msg')
@@ -108,16 +90,16 @@ When sending logs to console, they are mapped to `info`, `warn`, `error`, and `d
108
90
  You can also add your own custom levels:
109
91
 
110
92
  ```ts
111
- import { config, getLogger, logLevel } from 'standard-log'
93
+ import { createStandardLog } from 'standard-log'
112
94
 
113
- config({
95
+ const standardLog = createStandardLog({
114
96
  customLevels: {
115
97
  'important': logLevel.warn + 1,
116
98
  'silly': logLevel.debug + 1
117
99
  }
118
100
  })
119
101
 
120
- const log = getLogger<'silly' | 'important'>('custom')
102
+ const log = standardLog.getLogger('custom')
121
103
  log.important('this is an important message')
122
104
  log.silly('oh silly')
123
105
  ```
@@ -128,14 +110,14 @@ Besides printing the logs to console,
128
110
  you can use different reporters to save the logs in memory, file, service, or others.
129
111
 
130
112
  ```ts
131
- import { config, createConsoleLogReporter, createMemoryLogReporter } from 'standard-log'
113
+ import { createStandardLog, createConsoleLogReporter, createMemoryLogReporter } from 'standard-log'
132
114
 
133
- config({
115
+ createStandardLog({
134
116
  reporters: [createConsoleLogReporter(), createMemoryLogReporter()]
135
117
  })
136
118
  ```
137
119
 
138
- Some reporters allows you to format the logs and/or filter them.
120
+ Some reporters allow you to format the logs and/or filter them.
139
121
  Using the console log reporter as an example:
140
122
 
141
123
  ```ts
@@ -149,37 +131,10 @@ createConsoleLogReporter({
149
131
 
150
132
  Here are some additional reporters:
151
133
 
152
- - [`standard-log-color`](https://github.com/unional/standard-log/tree/master/packages/color)
134
+ - [`standard-log-color`]
153
135
  - `standard-log-file` (TODO)
154
136
  - `standard-log-syslog` (TODO)
155
137
 
156
- ### Capture Logs
157
-
158
- You can temporarily capture logs by `captureLogs()`.
159
- This is useful when you are writing tests.
160
-
161
- ```ts
162
- import { getLogger, captureLogs } from 'standard-log'
163
- import a from 'assertron'
164
-
165
- test('your test', () => {
166
- function foo() {
167
- const log = getLogger('foo logger')
168
- // this log will not be sent to normal reporters
169
- log.info('some messages')
170
- return 'miku'
171
- }
172
- const log = getLogger('foo logger')
173
- const [result, logs] = captureLogs(log, foo)
174
-
175
- a.satisfies(logs, [{ args: ['some messages']}])
176
- a.equals('miku', result)
177
-
178
- // rewriting the logs
179
- logs.forEach(entry => log.write(entry))
180
- })
181
- ```
182
-
183
138
  ### Suppress log
184
139
 
185
140
  You can temporarily suppress logs by `suppressLogs()`.
@@ -193,66 +148,35 @@ const log = getLogger('some logger')
193
148
  suppressLogs(() => log.info('not logged'), log)
194
149
  ```
195
150
 
196
- ## Browser usage
197
-
198
- The package comes with a pre-bundled file under `dist`.
199
- To use it, you also need to load [`global-store`](https://github.com/unional/global-store)
200
-
201
- If you are building a library and bundle it, make sure you mark `global-store` as externals.
202
- You can check out [`global-store`](https://github.com/unional/global-store) for more information.
203
-
204
- ## testing
151
+ ## Testing
205
152
 
206
153
  During test,
207
- you should configure `standard-log` to `test` mode and use `MemoryReporter` to capture the logs.
154
+ you should use `createStandardLogForTest` which includes a `MemoryReporter` to capture the logs.
208
155
 
209
156
  ```ts
210
- import { config, createMemoryReporter } from 'standard-log'
157
+ import { createStandardLogForTest, createMemoryReporter } from 'standard-log'
211
158
 
212
159
  test('your test', () => {
213
- const reporter = createMemoryLogReporter()
214
- config({
215
- reporters: [reporter],
216
- mode: 'test'
217
- })
160
+ const standardLog = createStandardLogForTest()
161
+ yourApp.standardLog = standardLog
218
162
 
219
- // do your thing...
163
+ // do your thing...
220
164
 
221
- const messages = reporter.getLogMessage() // or getLogMessageWithLevel()
165
+ const messages = standardLog.reporter.getLogMessage() // or getLogMessageWithLevel()
222
166
  // validate the message if you want to
223
167
  })
224
168
  ```
225
169
 
226
- And to simplify things, you can use the `configForTest()` function:
227
-
228
- ```ts
229
- import { configForTest } from 'standard-log'
230
-
231
- test('your test', () => {
232
- const { reporter } = configForTest()
233
-
234
- // do your thing...
235
- })
236
- ```
237
-
238
- [npm-image]: https://img.shields.io/npm/v/standard-log.svg?style=flat
239
- [npm-url]: https://www.npmjs.com/package/standard-log
170
+ [`just-func`]: https://github.com/justland/just-func-typescript
171
+ [`standard-log`]: https://github.com/unional/standard-log
172
+ [`standard-log-color`]: https://github.com/unional/standard-log/tree/master/packages/color
173
+ [codecov-image]: https://codecov.io/gh/unional/standard-log/branch/master/graph/badge.svg
174
+ [codecov-url]: https://codecov.io/gh/unional/standard-log
240
175
  [downloads-image]: https://img.shields.io/npm/dm/standard-log.svg?style=flat
241
176
  [downloads-url]: https://npmjs.org/package/standard-log
242
-
243
- [github-nodejs]: https://github.com/unional/standard-log/workflows/Node%20CI/badge.svg
244
177
  [github-action-url]: https://github.com/unional/standard-log/actions
245
- [codecov-image]: https://codecov.io/gh/unional/standard-log/branch/master/graph/badge.svg
246
- [codecov-url]: https://codecov.io/gh/unional/standard-log
247
- [codacy-grade]: https://api.codacy.com/project/badge/Grade/707f89609508442486050d207ec5bd78
248
- [codacy-grade-url]: https://www.codacy.com/app/homawong/standard-log?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=unional/standard-log&amp;utm_campaign=Badge_Grade
249
- [codacy-coverage]: https://api.codacy.com/project/badge/Coverage/707f89609508442486050d207ec5bd78
250
- [codacy-coverage-url]: https://www.codacy.com/manual/homawong/standard-log?utm_source=github.com&utm_medium=referral&utm_content=unional/standard-log&utm_campaign=Badge_Coverage
251
-
252
- [greenkeeper-image]: https://badges.greenkeeper.io/unional/standard-log.svg
253
- [greenkeeper-url]: https://greenkeeper.io/
254
-
178
+ [github-nodejs]: https://github.com/unional/standard-log/workflows/Node%20CI/badge.svg
179
+ [npm-image]: https://img.shields.io/npm/v/standard-log.svg?style=flat
180
+ [npm-url]: https://www.npmjs.com/package/standard-log
255
181
  [vscode-image]: https://img.shields.io/badge/vscode-ready-green.svg
256
182
  [vscode-url]: https://code.visualstudio.com/
257
- [wallaby-image]: https://img.shields.io/badge/wallaby.js-configured-green.svg
258
- [wallaby-url]: https://wallabyjs.com
@@ -1,9 +1,9 @@
1
- import { LogFormatter, LogReporter, LogReporterOptions } from '../types.js';
2
- import { Console } from './types.js';
1
+ import type { ConsoleLike, LogFormatter, LogReporter, LogReporterOptions } from './types.js';
2
+ export declare function toConsoleMethod(level: number): "error" | "warn" | "info" | "debug";
3
+ export declare type ConsoleLogFormatter = LogFormatter<any[]>;
3
4
  export declare type ConsoleLogReporter = LogReporter<any[]> & {
4
- console: Console;
5
+ console: ConsoleLike;
5
6
  };
6
- export declare type ConsoleLogFormatter = LogFormatter<any[]>;
7
7
  export declare type ConsoleLogReporterOptions = LogReporterOptions<any[]>;
8
8
  export declare function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter;
9
- //# sourceMappingURL=createConsoleLogReporter.d.ts.map
9
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAY,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEtG,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,uCAS5C;AAmCD,oBAAY,mBAAmB,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,CAAA;AACrD,oBAAY,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAA;AAC9E,oBAAY,yBAAyB,GAAG,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAA;AAEjE,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,kBAAkB,CAiBhG"}
package/cjs/console.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConsoleLogReporter = exports.toConsoleMethod = void 0;
4
+ var type_plus_1 = require("type-plus");
5
+ var logLevels_js_1 = require("./logLevels.js");
6
+ var platform_js_1 = require("./platform.js");
7
+ var formatter_js_1 = require("./formatter.js");
8
+ function toConsoleMethod(level) {
9
+ switch (true) {
10
+ // edge case in case none is somehow written
11
+ case (level <= 0): return 'debug';
12
+ case (level <= logLevels_js_1.logLevels.error): return 'error';
13
+ case (level <= logLevels_js_1.logLevels.warn): return 'warn';
14
+ case (level <= logLevels_js_1.logLevels.info): return 'info';
15
+ default: return 'debug';
16
+ }
17
+ }
18
+ exports.toConsoleMethod = toConsoleMethod;
19
+ // istanbul ignore next
20
+ /* eslint-disable no-console */
21
+ function buildPolyfillConsole() {
22
+ // old phantomjs does not have bind function
23
+ var hasBind = !!console.log.bind;
24
+ if (hasBind) {
25
+ return {
26
+ // Node@9.3 or below has `console.debug = undefined` or it doesn't log
27
+ // Should use `console.log()` in those case.
28
+ debug: ((0, platform_js_1.isConsoleDebugAvailable)() ? console.debug : console.log).bind(console),
29
+ // the `typeof` guards against IE where `console.log.apply()`
30
+ // results in error `Object doesn't support property or method 'apply'`
31
+ info: (typeof console.info === 'function' ? console.info : console.log).bind(console),
32
+ warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),
33
+ error: (typeof console.error === 'function' ? console.error : console.log).bind(console)
34
+ };
35
+ }
36
+ else {
37
+ return {
38
+ debug: buildFn((0, platform_js_1.isConsoleDebugAvailable)() ? 'debug' : 'log'),
39
+ info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),
40
+ warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),
41
+ error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),
42
+ };
43
+ }
44
+ }
45
+ // istanbul ignore next
46
+ function buildFn(name) {
47
+ return function () {
48
+ var args = [];
49
+ for (var _i = 0; _i < arguments.length; _i++) {
50
+ args[_i] = arguments[_i];
51
+ }
52
+ console[name].apply(console, args);
53
+ };
54
+ }
55
+ function createConsoleLogReporter(options) {
56
+ var _a = (0, type_plus_1.required)({ id: 'console', formatter: formatter_js_1.plainLogFormatter }, options), id = _a.id, formatter = _a.formatter, filter = _a.filter;
57
+ if (!platform_js_1.polyfill.console)
58
+ platform_js_1.polyfill.console = buildPolyfillConsole();
59
+ return Object.freeze({
60
+ id: id,
61
+ isConsoleReporter: true,
62
+ get formatter() { return formatter; },
63
+ get filter() { return filter; },
64
+ console: platform_js_1.polyfill.console,
65
+ write: function (entry) {
66
+ var _a;
67
+ if (filter && !filter(entry))
68
+ return;
69
+ var values = formatter(entry);
70
+ var method = toConsoleMethod(entry.level);
71
+ (_a = this.console)[method].apply(_a, values);
72
+ }
73
+ });
74
+ }
75
+ exports.createConsoleLogReporter = createConsoleLogReporter;
76
+ //# sourceMappingURL=console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.js","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,+CAA0C;AAC1C,6CAAiE;AACjE,+CAAkD;AAGlD,SAAgB,eAAe,CAAC,KAAa;IAC3C,QAAQ,IAAI,EAAE;QACZ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AAA,CAAC,CAAC;QACpC,IAAI,MAAM,KAAK,OAAO,MAAM,CAAA,CAAC,CAAC;QAC9B,OAAO,EAAE,sBAAQ,CAAC,OAAO;QACzB,KAAK,EAAL,UAAM,KAAe;;YACnB,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAM;YACpC,IAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;YAC/B,IAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC3C,CAAA,KAAA,IAAI,CAAC,OAAO,CAAA,CAAC,MAAM,CAAC,WAAI,MAAM,EAAC;QACjC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAjBD,4DAiBC","sourcesContent":["import { required } from 'type-plus'\nimport { logLevels } from './logLevels.js'\nimport { isConsoleDebugAvailable, polyfill } from './platform.js'\nimport { plainLogFormatter } from './formatter.js'\nimport type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\n\nexport function toConsoleMethod(level: number) {\n switch (true) {\n // edge case in case none is somehow written\n case (level <= 0): return 'debug'\n case (level <= logLevels.error): return 'error'\n case (level <= logLevels.warn): return 'warn'\n case (level <= logLevels.info): return 'info'\n default: return 'debug'\n }\n}\n\n// istanbul ignore next\n/* eslint-disable no-console */\nfunction buildPolyfillConsole() {\n // old phantomjs does not have bind function\n const hasBind = !!console.log.bind as boolean\n if (hasBind) {\n return {\n // Node@9.3 or below has `console.debug = undefined` or it doesn't log\n // Should use `console.log()` in those case.\n debug: (isConsoleDebugAvailable() ? console.debug : console.log).bind(console),\n // the `typeof` guards against IE where `console.log.apply()`\n // results in error `Object doesn't support property or method 'apply'`\n info: (typeof console.info === 'function' ? console.info : console.log).bind(console),\n warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),\n error: (typeof console.error === 'function' ? console.error : console.log).bind(console)\n }\n }\n else {\n return {\n debug: buildFn(isConsoleDebugAvailable() ? 'debug' : 'log'),\n info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),\n warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),\n error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),\n }\n }\n}\n\n// istanbul ignore next\nfunction buildFn(name: 'debug' | 'info' | 'warn' | 'error' | 'log') {\n return function (...args: any[]) { console[name](...args) }\n}\n\n\nexport type ConsoleLogFormatter = LogFormatter<any[]>\nexport type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }\nexport type ConsoleLogReporterOptions = LogReporterOptions<any[]>\n\nexport function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {\n const { id, formatter, filter } = required({ id: 'console', formatter: plainLogFormatter }, options)\n if (!polyfill.console) polyfill.console = buildPolyfillConsole()\n\n return Object.freeze({\n id,\n isConsoleReporter: true,\n get formatter() { return formatter },\n get filter() { return filter },\n console: polyfill.console,\n write(entry: LogEntry) {\n if (filter && !filter(entry)) return\n const values = formatter(entry)\n const method = toConsoleMethod(entry.level)\n this.console[method](...values)\n }\n })\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=console.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.spec.d.ts","sourceRoot":"","sources":["../ts/console.spec.ts"],"names":[],"mappings":""}
@@ -1,48 +1,42 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var assertron_1 = __importDefault(require("assertron"));
7
- var index_js_1 = require("../index.js");
8
- var store_js_1 = require("../store.js");
9
- var testUtil_js_1 = require("../testUtil.js");
10
- describe('production checks', function () {
11
- beforeEach(function () { return store_js_1.store.reset(); });
12
- test('set filter during production mode throws', function () {
13
- (0, index_js_1.config)({ mode: 'production' });
14
- var reporter = (0, index_js_1.createConsoleLogReporter)();
15
- assertron_1.default.throws(function () { reporter.filter = function () { return true; }; }, index_js_1.ProhibitedDuringProduction);
3
+ var standardLog_js_1 = require("./standardLog.js");
4
+ var index_js_1 = require("./index.js");
5
+ var platform_js_1 = require("./platform.js");
6
+ describe('toConsoleMethod()', function () {
7
+ it('converts any level to standard console method names: debug, info, warn, error', function () {
8
+ expect((0, index_js_1.toConsoleMethod)(1)).toEqual('error');
9
+ expect((0, index_js_1.toConsoleMethod)(399)).toEqual('error');
10
+ expect((0, index_js_1.toConsoleMethod)(400)).toEqual('error');
11
+ expect((0, index_js_1.toConsoleMethod)(401)).toEqual('warn');
12
+ expect((0, index_js_1.toConsoleMethod)(499)).toEqual('warn');
13
+ expect((0, index_js_1.toConsoleMethod)(500)).toEqual('warn');
14
+ expect((0, index_js_1.toConsoleMethod)(501)).toEqual('info');
15
+ expect((0, index_js_1.toConsoleMethod)(700)).toEqual('info');
16
+ expect((0, index_js_1.toConsoleMethod)(701)).toEqual('debug');
17
+ expect((0, index_js_1.toConsoleMethod)(800)).toEqual('debug');
18
+ expect((0, index_js_1.toConsoleMethod)(801)).toEqual('debug');
19
+ expect((0, index_js_1.toConsoleMethod)(Infinity)).toEqual('debug');
16
20
  });
17
- it('set filter throws with ssf at call site', function () {
18
- (0, index_js_1.config)({ mode: 'production' });
19
- var reporter = (0, index_js_1.createConsoleLogReporter)();
20
- var err = assertron_1.default.throws(function () { reporter.filter = function () { return true; }; }, index_js_1.ProhibitedDuringProduction);
21
- (0, testUtil_js_1.assertSSF)(err, __filename);
22
- });
23
- var idFormatter = function (entry) { return [entry.id]; };
24
- test('set formatter during production mode throws', function () {
25
- (0, index_js_1.config)({ mode: 'production' });
26
- var reporter = (0, index_js_1.createConsoleLogReporter)();
27
- assertron_1.default.throws(function () { return reporter.formatter = idFormatter; }, index_js_1.ProhibitedDuringProduction);
28
- });
29
- it('set formatter throws with ssf at call site', function () {
30
- (0, index_js_1.config)({ mode: 'production' });
31
- var reporter = (0, index_js_1.createConsoleLogReporter)();
32
- var err = assertron_1.default.throws(function () { return reporter.formatter = idFormatter; }, index_js_1.ProhibitedDuringProduction);
33
- (0, testUtil_js_1.assertSSF)(err, __filename);
21
+ it('converts to debug for 0 (none) or negative (not valid) level', function () {
22
+ // these are invalid input.
23
+ // so instead of hiding them and not logged,
24
+ // log them so that it is easier to discover.
25
+ expect((0, index_js_1.toConsoleMethod)(-1)).toEqual('debug');
26
+ expect((0, index_js_1.toConsoleMethod)(0)).toEqual('debug');
34
27
  });
35
28
  });
36
- describe('unit tests', function () {
37
- beforeEach(function () { return (0, index_js_1.configForTest)(); });
38
- describe('rendering tests', function () {
39
- test('plain rendering', function () {
40
- var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: index_js_1.plainLogFormatter });
41
- ['emergency', 'info', 'warn', 'debug'].forEach(function (level) {
42
- reporter.write({ id: 'plain', level: index_js_1.logLevels[level], args: ['hello', 'world'], timestamp: new Date() });
43
- });
29
+ describe('rendering tests', function () {
30
+ test('plain rendering', function () {
31
+ var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: index_js_1.plainLogFormatter });
32
+ ['emergency', 'info', 'warn', 'debug'].forEach(function (level) {
33
+ reporter.write({ id: 'plain', level: index_js_1.logLevels[level], args: ['hello', 'world'], timestamp: new Date() });
44
34
  });
45
35
  });
36
+ });
37
+ describe('createConsoleLogReporter', function () {
38
+ var fakeConsole = createFakeConsole();
39
+ beforeEach(function () { return platform_js_1.polyfill.console = fakeConsole = createFakeConsole(); });
46
40
  describe('id', function () {
47
41
  test('default is "console"', function () {
48
42
  var reporter = (0, index_js_1.createConsoleLogReporter)();
@@ -57,7 +51,6 @@ describe('unit tests', function () {
57
51
  test('error, alert, critical and emergency logs are written to console.error', function () {
58
52
  var id = 'log';
59
53
  var reporter = (0, index_js_1.createConsoleLogReporter)();
60
- var fakeConsole = reporter.console = createFakeConsole();
61
54
  reporter.write({ id: id, level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
62
55
  reporter.write({ id: id, level: index_js_1.logLevels.critical, args: ['critical'], timestamp: new Date() });
63
56
  reporter.write({ id: id, level: index_js_1.logLevels.alert, args: ['alert'], timestamp: new Date() });
@@ -67,14 +60,12 @@ describe('unit tests', function () {
67
60
  test('warn logs are written to console.warn', function () {
68
61
  var id = 'log';
69
62
  var reporter = (0, index_js_1.createConsoleLogReporter)();
70
- var fakeConsole = reporter.console = createFakeConsole();
71
63
  reporter.write({ id: id, level: index_js_1.logLevels.warn, args: ['warn'], timestamp: new Date() });
72
64
  expect(fakeConsole.warns.length).toBe(1);
73
65
  });
74
66
  test('notice and info logs are written to console.info', function () {
75
67
  var id = 'log';
76
68
  var reporter = (0, index_js_1.createConsoleLogReporter)();
77
- var fakeConsole = reporter.console = createFakeConsole();
78
69
  reporter.write({ id: id, level: index_js_1.logLevels.notice, args: ['notice'], timestamp: new Date() });
79
70
  reporter.write({ id: id, level: index_js_1.logLevels.info, args: ['info'], timestamp: new Date() });
80
71
  expect(fakeConsole.infos.length).toBe(2);
@@ -82,7 +73,6 @@ describe('unit tests', function () {
82
73
  test('debug, trace, and planck logs are written to console.debug', function () {
83
74
  var id = 'log';
84
75
  var reporter = (0, index_js_1.createConsoleLogReporter)();
85
- var fakeConsole = reporter.console = createFakeConsole();
86
76
  reporter.write({ id: id, level: index_js_1.logLevels.debug, args: ['debug'], timestamp: new Date() });
87
77
  reporter.write({ id: id, level: index_js_1.logLevels.trace, args: ['trace'], timestamp: new Date() });
88
78
  reporter.write({ id: id, level: index_js_1.logLevels.planck, args: ['planck'], timestamp: new Date() });
@@ -90,19 +80,24 @@ describe('unit tests', function () {
90
80
  });
91
81
  });
92
82
  describe('custom logs', function () {
93
- afterEach(function () { return (0, index_js_1.clearCustomLogLevel)(); });
94
83
  test('are written according to their log level value', function () {
95
- (0, index_js_1.addCustomLogLevel)('high', 50);
96
- (0, index_js_1.addCustomLogLevel)('important', 450);
97
- (0, index_js_1.addCustomLogLevel)('interest', 650);
98
- (0, index_js_1.addCustomLogLevel)('silly', 1000);
99
84
  var id = 'log';
100
85
  var reporter = (0, index_js_1.createConsoleLogReporter)();
101
- var fakeConsole = reporter.console = createFakeConsole();
102
- reporter.write({ id: id, level: 50, args: ['a'], timestamp: new Date() });
103
- reporter.write({ id: id, level: 450, args: ['b'], timestamp: new Date() });
104
- reporter.write({ id: id, level: 650, args: ['c'], timestamp: new Date() });
105
- reporter.write({ id: id, level: 1000, args: ['d'], timestamp: new Date() });
86
+ var sl = (0, standardLog_js_1.createStandardLog)({
87
+ logLevel: index_js_1.logLevels.all,
88
+ customLevels: {
89
+ 'high': 50,
90
+ 'important': 450,
91
+ 'interest': 650,
92
+ 'silly': 1000
93
+ },
94
+ reporters: [reporter]
95
+ });
96
+ var log = sl.getLogger([id]);
97
+ log.high('a');
98
+ log.important('b');
99
+ log.interest('c');
100
+ log.silly('d');
106
101
  expect(fakeConsole.errors.length).toBe(1);
107
102
  expect(fakeConsole.warns.length).toBe(1);
108
103
  expect(fakeConsole.infos.length).toBe(1);
@@ -114,37 +109,24 @@ describe('unit tests', function () {
114
109
  test('use specific formatter', function () {
115
110
  var id = 'id-only';
116
111
  var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: idFormatter });
117
- var fakeConsole = reporter.console = createFakeConsole();
112
+ expect(reporter.formatter).toBe(idFormatter);
118
113
  reporter.write({ id: id, level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
119
114
  expect(fakeConsole.errors).toEqual([['id-only']]);
120
115
  });
121
- test('formatter can be changed afterward', function () {
122
- var reporter = (0, index_js_1.createConsoleLogReporter)();
123
- var formatter = reporter.formatter;
124
- reporter.formatter = idFormatter;
125
- expect(reporter.formatter).not.toEqual(formatter);
126
- });
127
116
  });
128
117
  describe('filter', function () {
129
118
  var filter = function (entry) { return entry.id !== 'secret'; };
130
119
  test('use specific filter', function () {
131
120
  var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: idFormatter, filter: filter });
132
- var fakeConsole = reporter.console = createFakeConsole();
121
+ expect(reporter.filter).toBe(filter);
133
122
  reporter.write({ id: 'normal', level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
134
123
  reporter.write({ id: 'secret', level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
135
124
  expect(fakeConsole.errors).toEqual([['normal']]);
136
125
  });
137
- test('can change filter', function () {
138
- var reporter = (0, index_js_1.createConsoleLogReporter)();
139
- var filter = reporter.filter;
140
- reporter.filter = function (entry) { return entry.id !== 'secret'; };
141
- expect(reporter.filter).not.toEqual(filter);
142
- });
143
126
  });
144
127
  test('write log entry with multiple arguments', function () {
145
128
  var id = 'log';
146
129
  var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: index_js_1.plainLogFormatter });
147
- var fakeConsole = reporter.console = createFakeConsole();
148
130
  var entry = { id: id, level: index_js_1.logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() };
149
131
  reporter.write(entry);
150
132
  expect(fakeConsole.infos).toEqual([
@@ -192,4 +174,4 @@ function createFakeConsole() {
192
174
  }
193
175
  };
194
176
  }
195
- //# sourceMappingURL=createConsoleLogReporter.spec.js.map
177
+ //# sourceMappingURL=console.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.spec.js","sourceRoot":"","sources":["../ts/console.spec.ts"],"names":[],"mappings":";;AAAA,mDAAoD;AACpD,uCAGmB;AACnB,6CAAwC;AAExC,QAAQ,CAAC,mBAAmB,EAAE;IAC5B,EAAE,CAAC,+EAA+E,EAAE;QAClF,MAAM,CAAC,IAAA,0BAAe,EAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC7C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAE7C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,C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AAA;QACL,MAAM,QAAA;QACN,KAAK,EAAL;YAAM,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QAC3C,IAAI,EAAJ;YAAK,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QACzC,IAAI,EAAJ;YAAK,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;QACzC,KAAK,EAAL;YAAM,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;KAC5C,CAAA;AACH,CAAC","sourcesContent":["import { createStandardLog } from './standardLog.js'\nimport {\n ConsoleLogFormatter, createConsoleLogReporter,\n LogFilter, logLevels, plainLogFormatter, toConsoleMethod\n} from './index.js'\nimport { polyfill } from './platform.js'\n\ndescribe('toConsoleMethod()', () => {\n it('converts any level to standard console method names: debug, info, warn, error', () => {\n expect(toConsoleMethod(1)).toEqual('error')\n expect(toConsoleMethod(399)).toEqual('error')\n expect(toConsoleMethod(400)).toEqual('error')\n\n expect(toConsoleMethod(401)).toEqual('warn')\n expect(toConsoleMethod(499)).toEqual('warn')\n expect(toConsoleMethod(500)).toEqual('warn')\n\n expect(toConsoleMethod(501)).toEqual('info')\n expect(toConsoleMethod(700)).toEqual('info')\n\n expect(toConsoleMethod(701)).toEqual('debug')\n expect(toConsoleMethod(800)).toEqual('debug')\n expect(toConsoleMethod(801)).toEqual('debug')\n expect(toConsoleMethod(Infinity)).toEqual('debug')\n })\n it('converts to debug for 0 (none) or negative (not valid) level', () => {\n // these are invalid input.\n // so instead of hiding them and not logged,\n // log them so that it is easier to discover.\n expect(toConsoleMethod(-1)).toEqual('debug')\n expect(toConsoleMethod(0)).toEqual('debug')\n })\n})\ndescribe('rendering tests', () => {\n test('plain rendering', () => {\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter });\n ['emergency', 'info', 'warn', 'debug'].forEach(level => {\n reporter.write({ id: 'plain', level: (logLevels as any)[level], args: ['hello', 'world'], timestamp: new Date() })\n })\n })\n})\n\n\ndescribe('createConsoleLogReporter', () => {\n let fakeConsole = createFakeConsole()\n beforeEach(() => polyfill.console = fakeConsole = createFakeConsole())\n\n describe('id', () => {\n test('default is \"console\"', () => {\n const reporter = createConsoleLogReporter()\n expect(reporter.id).toBe('console')\n })\n test('can be overridden', () => {\n const reporter = createConsoleLogReporter({ id: 'neo-console' })\n expect(reporter.id).toBe('neo-console')\n })\n })\n\n describe('log level', () => {\n test('error, alert, critical and emergency logs are written to console.error', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.critical, args: ['critical'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.alert, args: ['alert'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.error, args: ['error'], timestamp: new Date() })\n\n expect(fakeConsole.errors.length).toBe(4)\n })\n\n test('warn logs are written to console.warn', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.warn, args: ['warn'], timestamp: new Date() })\n\n expect(fakeConsole.warns.length).toBe(1)\n })\n\n test('notice and info logs are written to console.info', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.notice, args: ['notice'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.info, args: ['info'], timestamp: new Date() })\n\n expect(fakeConsole.infos.length).toBe(2)\n })\n\n\n test('debug, trace, and planck logs are written to console.debug', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.debug, args: ['debug'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.trace, args: ['trace'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.planck, args: ['planck'], timestamp: new Date() })\n\n expect(fakeConsole.debugs.length).toBe(3)\n })\n })\n\n describe('custom logs', () => {\n test('are written according to their log level value', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n const sl = createStandardLog({\n logLevel: logLevels.all,\n customLevels: {\n 'high': 50,\n 'important': 450,\n 'interest': 650,\n 'silly': 1000\n },\n reporters: [reporter]\n })\n const log = sl.getLogger([id])\n log.high('a')\n log.important('b')\n log.interest('c')\n log.silly('d')\n\n expect(fakeConsole.errors.length).toBe(1)\n expect(fakeConsole.warns.length).toBe(1)\n expect(fakeConsole.infos.length).toBe(1)\n expect(fakeConsole.debugs.length).toBe(1)\n })\n })\n\n const idFormatter: ConsoleLogFormatter = (entry) => [entry.id]\n\n describe('formatter', () => {\n test('use specific formatter', () => {\n const id = 'id-only'\n const reporter = createConsoleLogReporter({ formatter: idFormatter })\n expect(reporter.formatter).toBe(idFormatter)\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['id-only']])\n })\n })\n\n describe('filter', () => {\n const filter: LogFilter = (entry) => entry.id !== 'secret'\n test('use specific filter', () => {\n const reporter = createConsoleLogReporter({ formatter: idFormatter, filter })\n expect(reporter.filter).toBe(filter)\n\n reporter.write({ id: 'normal', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id: 'secret', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['normal']])\n })\n })\n\n test('write log entry with multiple arguments', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter })\n\n const entry = { id, level: logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() }\n\n reporter.write(entry)\n\n expect(fakeConsole.infos).toEqual([\n [entry.timestamp.toISOString(), 'log', '(INFO)', 'a', 'b', 'c']\n ])\n })\n})\n\nfunction createFakeConsole() {\n const errors: any[] = []\n const infos: any[] = []\n const warns: any[] = []\n const debugs: any[] = []\n return {\n errors,\n infos,\n warns,\n debugs,\n error(...args: any[]) { errors.push(args) },\n info(...args: any[]) { infos.push(args) },\n warn(...args: any[]) { warns.push(args) },\n debug(...args: any[]) { debugs.push(args) }\n }\n}\n"]}