standard-log 8.0.0 → 9.0.1

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 (614) 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 -55
  9. package/cjs/console.spec.js.map +1 -0
  10. package/cjs/errors.d.ts +1 -11
  11. package/cjs/errors.d.ts.map +1 -1
  12. package/cjs/errors.js +3 -45
  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 +548 -0
  70. package/cjs/standardLog.spec.js.map +1 -0
  71. package/cjs/testUtil.d.ts +7 -4
  72. package/cjs/testUtil.d.ts.map +1 -1
  73. package/cjs/testUtil.js +16 -13
  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 +326 -1079
  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 +309 -1146
  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 -52
  93. package/esm/console.spec.js.map +1 -0
  94. package/esm/errors.d.ts +1 -11
  95. package/esm/errors.d.ts.map +1 -1
  96. package/esm/errors.js +2 -36
  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 +446 -0
  153. package/esm/standardLog.spec.js.map +1 -0
  154. package/esm/testUtil.d.ts +7 -4
  155. package/esm/testUtil.d.ts.map +1 -1
  156. package/esm/testUtil.js +11 -11
  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 +12 -20
  162. package/ts/console.ts +72 -0
  163. package/ts/errors.ts +2 -14
  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 -66
  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 -19
  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 -481
  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 -86
  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 -111
  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 -5
  368. package/cjs/utils.d.ts.map +0 -1
  369. package/cjs/utils.js +0 -14
  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 -61
  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 -14
  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 -381
  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 -81
  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 -98
  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 -5
  569. package/esm/utils.d.ts.map +0 -1
  570. package/esm/utils.js +0 -10
  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 -42
  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 -66
  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/testUtil.ts +0 -19
  612. package/ts/typesInternal.ts +0 -21
  613. package/ts/utils.ts +0 -9
  614. package/ts/writeToReporters.ts +0 -20
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logStore.js","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAGtE,MAAM,UAAU,cAAc,CAAC,OAA2B;IACxD,OAAO;QACL,OAAO,EAAE,EAAE;QACX,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC,wBAAwB,EA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ey } from 'type-plus'\nimport { createConsoleLogReporter } from './console.js'\nimport { logLevels, toLogLevel, toLogLevelName } from './logLevels.js'\nimport type { Logger, LogLevel, LogReporter, StandardLogOptions } from './types.js'\n\nexport function createLogStore(options: StandardLogOptions): LogStore {\n return {\n loggers: {},\n reporters: options.reporters || [createConsoleLogReporter()],\n logLevel: options.logLevel,\n logLevelStore: logLevelStore(options)\n }\n}\n\nexport interface LogStore {\n loggers: Record<string, Logger>,\n reporters: LogReporter[],\n logLevel: LogLevel,\n logLevelStore: ReturnType<typeof logLevelStore>\n}\n\nexport interface LogLevelStoreOptions {\n customLevels?: Record<string, number>\n}\n\nexport function logLevelStore(options: LogLevelStoreOptions) {\n const customLevels = options.customLevels || {}\n\n const store = {\n customLevels,\n customLevelsReverse: reduceByKey(customLevels, (p, k) => {\n p[customLevels[k]] = k\n return p\n }, {} as Record<number, string>)\n }\n return {\n getName(level: number) {\n return store.customLevelsReverse[level] ?? toLogLevelName(level)\n },\n getLevel(name: string) {\n return store.customLevels[name] ?? toLogLevel(name)\n },\n getAllLevels() {\n return reduceKey(logLevels, (result, name) => {\n if (name !== 'none' && name !== 'all') result.push({ name, level: logLevels[name] })\n\n return result\n }, mapKey(store.customLevels, name => ({ name, level: store.customLevels[name] })))\n }\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=logStore.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logStore.spec.d.ts","sourceRoot":"","sources":["../ts/logStore.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,93 @@
1
+ import { forEachKey } from 'type-plus';
2
+ import { logLevels } from './logLevels.js';
3
+ import { logLevelStore } from './logStore.js';
4
+ import { rangeEntries } from './testUtil.js';
5
+ describe('getName()', () => {
6
+ it.each([
7
+ ...rangeEntries(99, 100, 'emergency'),
8
+ ...rangeEntries(199, 200, 'alert'),
9
+ ...rangeEntries(299, 300, 'critical'),
10
+ ...rangeEntries(399, 400, 'error'),
11
+ ...rangeEntries(499, 500, 'warn'),
12
+ ...rangeEntries(599, 600, 'notice'),
13
+ ...rangeEntries(699, 700, 'info'),
14
+ ...rangeEntries(799, 800, 'debug'),
15
+ ...rangeEntries(899, 900, 'trace'),
16
+ ...rangeEntries(9999999, 10000000, 'planck')
17
+ ])('convert %i to %s', (level, logLevel) => {
18
+ const store = logLevelStore({ customLevels: {} });
19
+ expect(store.getName(level)).toBe(logLevel);
20
+ });
21
+ it('gets custom log level name', () => {
22
+ const store = logLevelStore({ customLevels: { 'cust-name': 144 } });
23
+ expect(store.getName(144)).toBe('cust-name');
24
+ });
25
+ });
26
+ describe('getLevel()', () => {
27
+ it('get default log levels', () => {
28
+ const store = logLevelStore({ customLevels: {} });
29
+ const names = [
30
+ 'emergency',
31
+ 'alert',
32
+ 'critical',
33
+ 'error',
34
+ 'warn',
35
+ 'notice',
36
+ 'info',
37
+ 'debug',
38
+ 'trace',
39
+ 'planck'
40
+ ];
41
+ expect(names.map(n => store.getLevel(n))).toEqual([
42
+ 100, 200, 300, 400, 500, 600, 700, 800, 900, Infinity
43
+ ]);
44
+ });
45
+ it('is case insensitive for default levels', () => {
46
+ const store = logLevelStore({ customLevels: {} });
47
+ const names = [
48
+ 'emerGency',
49
+ 'aleRt',
50
+ 'critIcal',
51
+ 'errOr',
52
+ 'warN',
53
+ 'nOtice',
54
+ 'iNfo',
55
+ 'deBug',
56
+ 'traCe',
57
+ 'planCk',
58
+ ];
59
+ expect(names.map(n => store.getLevel(n))).toEqual([
60
+ 100, 200, 300, 400, 500, 600, 700, 800, 900, Infinity
61
+ ]);
62
+ });
63
+ it('gets custom log level', () => {
64
+ const store = logLevelStore({ customLevels: { 'cust-get': 123 } });
65
+ expect(store.getLevel('cust-get')).toBe(123);
66
+ });
67
+ });
68
+ describe('getAllLevels()', () => {
69
+ it('gets all default log levels except none and all', () => {
70
+ const store = logLevelStore({ customLevels: {} });
71
+ const actual = store.getAllLevels();
72
+ forEachKey(logLevels, name => {
73
+ if (name === 'none' || name === 'all') {
74
+ expect(actual.find(x => x.name === name)).toBeUndefined();
75
+ }
76
+ else {
77
+ expect(actual.find(x => x.name === name)).toEqual({ name, level: logLevels[name] });
78
+ }
79
+ });
80
+ });
81
+ it('include custom level (even if they have the same level value as one of the default level)', () => {
82
+ const store = logLevelStore({
83
+ customLevels: {
84
+ 'info_a': 301,
85
+ 'info_b': logLevels.info
86
+ }
87
+ });
88
+ const actual = store.getAllLevels();
89
+ expect(actual.find(x => x.name === 'info_a')).toEqual({ name: 'info_a', level: 301 });
90
+ expect(actual.find(x => x.name === 'info_b')).toEqual({ name: 'info_b', level: logLevels.info });
91
+ });
92
+ });
93
+ //# sourceMappingURL=logStore.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logStore.spec.js","sourceRoot":"","sources":["../ts/logStore.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,IAAI,CAAC;QACN,GAAG,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,WAAW,CAAC;QACrC,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC;QAClC,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,CAAC;QACrC,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC;QAClC,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC;QACjC,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC;QACnC,GAAG,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC;QACj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from './logStore.js'\nimport { rangeEntries } from './testUtil.js'\n\ndescribe('getName()', () => {\n it.each([\n ...rangeEntries(99, 100, 'emergency'),\n ...rangeEntries(199, 200, 'alert'),\n ...rangeEntries(299, 300, 'critical'),\n ...rangeEntries(399, 400, 'error'),\n ...rangeEntries(499, 500, 'warn'),\n ...rangeEntries(599, 600, 'notice'),\n ...rangeEntries(699, 700, 'info'),\n ...rangeEntries(799, 800, 'debug'),\n ...rangeEntries(899, 900, 'trace'),\n ...rangeEntries(9999999, 10000000, 'planck')\n ])('convert %i to %s', (level: number, logLevel: string) => {\n const store = logLevelStore({ customLevels: {} })\n expect(store.getName(level)).toBe(logLevel)\n })\n it('gets custom log level name', () => {\n const store = logLevelStore({ customLevels: { 'cust-name': 144 } })\n expect(store.getName(144)).toBe('cust-name')\n })\n})\n\ndescribe('getLevel()', () => {\n it('get default log levels', () => {\n const store = logLevelStore({ customLevels: {} })\n const names = [\n 'emergency',\n 'alert',\n 'critical',\n 'error',\n 'warn',\n 'notice',\n 'info',\n 'debug',\n 'trace',\n 'planck'\n ]\n expect(names.map(n => store.getLevel(n))).toEqual([\n 100, 200, 300, 400, 500, 600, 700, 800, 900, Infinity\n ])\n })\n it('is case insensitive for default levels', () => {\n const store = logLevelStore({ customLevels: {} })\n const names = [\n 'emerGency',\n 'aleRt',\n 'critIcal',\n 'errOr',\n 'warN',\n 'nOtice',\n 'iNfo',\n 'deBug',\n 'traCe',\n 'planCk',\n ]\n expect(names.map(n => store.getLevel(n))).toEqual([\n 100, 200, 300, 400, 500, 600, 700, 800, 900, Infinity\n ])\n })\n it('gets custom log level', () => {\n const store = logLevelStore({ customLevels: { 'cust-get': 123 } })\n expect(store.getLevel('cust-get')).toBe(123)\n })\n})\n\ndescribe('getAllLevels()', () => {\n it('gets all default log levels except none and all', () => {\n const store = logLevelStore({ customLevels: {} })\n const actual = store.getAllLevels()\n forEachKey(logLevels, name => {\n if (name === 'none' || name === 'all') {\n expect(actual.find(x => x.name === name)).toBeUndefined()\n }\n else {\n expect(actual.find(x => x.name === name)).toEqual({ name, level: logLevels[name] })\n }\n })\n })\n it('include custom level (even if they have the same level value as one of the default level)', () => {\n const store = logLevelStore({\n customLevels: {\n 'info_a': 301,\n 'info_b': logLevels.info\n }\n })\n const actual = store.getAllLevels()\n expect(actual.find(x => x.name === 'info_a')).toEqual({ name: 'info_a', level: 301 })\n expect(actual.find(x => x.name === 'info_b')).toEqual({ name: 'info_b', level: logLevels.info })\n })\n})\n"]}
@@ -0,0 +1,6 @@
1
+ import type { StackTraceMeta } from '@just-func/types';
2
+ import { RequiredPick } from 'type-plus';
3
+ import { LogStore } from './logStore.js';
4
+ import type { Logger, LoggerOptions, LogMethodNames } from './types.js';
5
+ export declare function createLogger<T extends string = LogMethodNames>([store, id, { level, writeTo }]: [LogStore, string, RequiredPick<LoggerOptions, 'level'>], meta?: StackTraceMeta): Logger;
6
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAGxC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAyB,MAAM,EAAE,aAAa,EAAE,cAAc,EAAe,MAAM,YAAY,CAAA;AAG3G,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAC5D,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,OAAoB,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,EACtG,IAAI,CAAC,EAAE,cAAc,GACpB,MAAM,CAwDR"}
package/esm/logger.js ADDED
@@ -0,0 +1,74 @@
1
+ import { InvalidId } from './errors.js';
2
+ import { logLevels } from './logLevels.js';
3
+ export function createLogger([store, id, { level, writeTo = () => true }], meta) {
4
+ validateId(id, meta);
5
+ const [filter, reporters] = typeof writeTo === 'string'
6
+ ? [id => id === writeTo, store.reporters]
7
+ : writeTo instanceof RegExp
8
+ ? [id => writeTo.test(id), store.reporters]
9
+ : typeof writeTo === 'function'
10
+ ? [writeTo, store.reporters]
11
+ : [() => true, [writeTo]];
12
+ function write(entry) {
13
+ writeToReporters(reporters, entry, filter);
14
+ }
15
+ const logger = {
16
+ level,
17
+ write
18
+ };
19
+ Object.defineProperties(logger, {
20
+ id: { value: id, writable: false },
21
+ count: {
22
+ writable: false,
23
+ value: ((counter) => (...args) => {
24
+ const level = logLevels.debug;
25
+ if (shouldLog(store, level, logger.level))
26
+ write({
27
+ id,
28
+ level,
29
+ args: [++counter, ...args],
30
+ timestamp: new Date()
31
+ });
32
+ })(0)
33
+ },
34
+ on: {
35
+ writable: false,
36
+ value: (level, logFn) => {
37
+ const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level) : level;
38
+ if (shouldLog(store, logLevel, logger.level)) {
39
+ const methodName = store.logLevelStore.getName(logLevel);
40
+ const bindedMethod = logger[methodName].bind(logger);
41
+ const result = logFn(bindedMethod);
42
+ if (result)
43
+ bindedMethod(result);
44
+ }
45
+ }
46
+ }
47
+ });
48
+ store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {
49
+ Object.defineProperty(logger, name, {
50
+ writable: false,
51
+ value: (...args) => {
52
+ if (shouldLog(store, level, logger.level))
53
+ write({ id, level, args, timestamp: new Date() });
54
+ }
55
+ });
56
+ });
57
+ return logger;
58
+ }
59
+ function validateId(id, meta) {
60
+ if (/[`~!#$%^&*()=+[\]{},|<>?]/.test(id))
61
+ throw new InvalidId(id, meta);
62
+ }
63
+ function writeToReporters(reporters, logEntry, filter) {
64
+ reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry));
65
+ }
66
+ /**
67
+ * Determines should you log.
68
+ * @param loggerLevel Log level of the logger.
69
+ * It can be undefined which the global log level will be used.
70
+ */
71
+ function shouldLog(store, targetLevel, loggerLevel) {
72
+ return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel);
73
+ }
74
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAK1C,MAAM,UAAU,YAAY,CAC1B,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,EAAE,CAA2D,EACtG,IAAqB;IAErB,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IACpB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAqD,OAAO,OAAO,KAAK,QAAQ;QACvG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;QACzC,CAAC,CAAC,OAAO,YAAY,MAAM;YACzB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;YAC3C,CAAC,CAAC,OAAO,OAAO,KAAK,UAAU;gBAC7B,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;gBAC5B,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAE/B,SAAS,KAAK,CAAC,KAAe;QAC5B,gBAAgB,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,MAAM,MAAM,GAAG;QACb,KAAK;QACL,KAAK;KACC,CAAA;IAER,MAAM,CAAC,gBAAgB,C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AC,OAAO,CAAC,SAAS,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE;QAC3E,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE;YAClC,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;gBACxB,IAAI,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC;oBAAE,KAAK,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAA;YAC9F,CAAC;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,UAAU,CAAC,EAAU,EAAE,IAAqB;IACnD,IAAI,2BAA2B,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AACzE,CAAC;AAED,SAAS,gBAAgB,CAAC,SAAwB,EAAE,QAAkB,EAAE,MAAuC;IAC7G,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAS,CAAC,CAAC,CAAA;AACtE,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAC,KAAe,EAAE,WAAqB,EAAE,WAAiC;IAC1F,OAAO,WAAW,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AAClF,CAAC","sourcesContent":["import type { StackTraceMeta } from '@just-func/types'\nimport { RequiredPick } from 'type-plus'\nimport { InvalidId } from './errors.js'\nimport { logLevels } from './logLevels.js'\nimport { LogStore } from './logStore.js'\nimport type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'\nimport { LogLevel } from './types.js'\n\nexport function createLogger<T extends string = LogMethodNames>(\n [store, id, { level, writeTo = () => true }]: [LogStore, string, RequiredPick<LoggerOptions, 'level'>],\n meta?: StackTraceMeta\n): Logger {\n validateId(id, meta)\n const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'\n ? [id => id === writeTo, store.reporters]\n : writeTo instanceof RegExp\n ? [id => writeTo.test(id), store.reporters]\n : typeof writeTo === 'function'\n ? [writeTo, store.reporters]\n : [() => true, [writeTo]]\n\n function write(entry: LogEntry) {\n writeToReporters(reporters, entry, filter)\n }\n\n const logger = {\n level,\n write\n } as any\n\n Object.defineProperties(logger, {\n id: { value: id, writable: false },\n count: {\n writable: false,\n value: ((counter) => (...args: any[]) => {\n const level = logLevels.debug\n if (shouldLog(store, level, logger.level))\n write({\n id,\n level,\n args: [++counter, ...args],\n timestamp: new Date()\n })\n })(0)\n },\n on: {\n writable: false,\n value: (level: number | T, logFn: LogFunction) => {\n const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level\n if (shouldLog(store, logLevel, logger.level)) {\n const methodName = store.logLevelStore.getName(logLevel)\n const bindedMethod = logger[methodName].bind(logger)\n const result = logFn(bindedMethod)\n if (result) bindedMethod(result)\n }\n }\n }\n })\n store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {\n Object.defineProperty(logger, name, {\n writable: false,\n value: (...args: any[]) => {\n if (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })\n }\n })\n })\n return logger\n}\n\nfunction validateId(id: string, meta?: StackTraceMeta) {\n if (/[`~!#$%^&*()=+[\\]{},|<>?]/.test(id)) throw new InvalidId(id, meta)\n}\n\nfunction writeToReporters(reporters: LogReporter[], logEntry: LogEntry, filter: (reporterId: string) => boolean) {\n reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))\n}\n\n/**\n * Determines should you log.\n * @param loggerLevel Log level of the logger.\n * It can be undefined which the global log level will be used.\n */\nfunction shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {\n return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from '../types.js';
1
+ import type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js';
2
2
  export declare type MemoryLogReporter = LogReporter<LogEntry> & {
3
3
  logs: LogEntry[];
4
4
  /**
@@ -11,4 +11,4 @@ export declare type MemoryLogReporter = LogReporter<LogEntry> & {
11
11
  export declare type MemoryLogFormatter = LogFormatter<LogEntry>;
12
12
  export declare function toMessageWithLevel(logs: LogEntry[]): string;
13
13
  export declare function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter;
14
- //# sourceMappingURL=MemoryLogReporter.d.ts.map
14
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEzF,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,sBAAsB,IAAI,MAAM,CAAA;CACjC,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAEvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAmBjG"}
package/esm/memory.js ADDED
@@ -0,0 +1,34 @@
1
+ import { required } from 'type-plus';
2
+ import { toInspectLogEntry } from './platform.js';
3
+ import { formatLogLevel } from './formatter.js';
4
+ export function toMessageWithLevel(logs) {
5
+ return logs.map(toInspectLogEntry)
6
+ .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)
7
+ .join('\n')
8
+ // if it has more than this log,
9
+ // we assume it is running under tests,
10
+ // and remove this log to simplify testing.
11
+ .replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, '');
12
+ }
13
+ export function createMemoryLogReporter(options) {
14
+ const { id, formatter, filter } = required({ id: 'memory', formatter: (e) => e }, options);
15
+ const logs = [];
16
+ return Object.freeze({
17
+ id,
18
+ get formatter() { return formatter; },
19
+ get filter() { return filter; },
20
+ logs,
21
+ write(entry) {
22
+ if (filter && !filter(entry))
23
+ return;
24
+ logs.push(formatter(entry));
25
+ },
26
+ getLogMessage() {
27
+ return logs.map(toInspectLogEntry)
28
+ .map(log => log.args.join(' '))
29
+ .join('\n');
30
+ },
31
+ getLogMessageWithLevel() { return toMessageWithLevel(logs); }
32
+ });
33
+ }
34
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAe/C,MAAM,UAAU,kBAAkB,CAAC,IAAgB;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC;SAC/B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;SAChE,IAAI,CAAC,IAAI,CAAC;QACX,gCAAgC;QAChC,uCAAuC;QACvC,2CAA2C;SAC1C,OAAO,CAAC,mEAAmE,EAAE,EAAE,CAAC,CAAA;AACrF,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAsC;IAC5E,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IACpG,MAAM,IAAI,GAAe,EAAE,CAAA;IAC3B,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,EAAE;QACF,IAAI,SAAS,KAAK,OAAO,SAAS,CAAA,CAAC,CAAC;QACpC,IAAI,MAAM,KAAK,OAAO,MAAM,CAAA,CAAC,CAAC;QAC9B,IAAI;QACJ,KAAK,CAAC,KAAe;YACnB,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAE,OAAM;YACpC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAA;QAC7B,CAAC;QACD,aAAa;YACX,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC;iBAC/B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;iBAC9B,IAAI,CAAC,IAAI,CAAC,CAAA;QACf,CAAC;QACD,sBAAsB,KAAK,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC;KAC7D,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { required } from 'type-plus'\nimport { toInspectLogEntry } from './platform.js'\nimport { formatLogLevel } from './formatter.js'\nimport type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\n\nexport type MemoryLogReporter = LogReporter<LogEntry> & {\n logs: LogEntry[],\n /**\n * Gets a simple log message for testing.\n * The message only contains arguments for each log entry.\n */\n getLogMessage(): string,\n getLogMessageWithLevel(): string\n}\n\nexport type MemoryLogFormatter = LogFormatter<LogEntry>\n\nexport function toMessageWithLevel(logs: LogEntry[]) {\n return logs.map(toInspectLogEntry)\n .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n .join('\\n')\n // if it has more than this log,\n // we assume it is running under tests,\n // and remove this log to simplify testing.\n .replace(/^\\(WARN\\) already configured for test, ignoring config\\(\\) call\\n/, '')\n}\n\nexport function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n const { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)\n const logs: LogEntry[] = []\n return Object.freeze({\n id,\n get formatter() { return formatter },\n get filter() { return filter },\n logs,\n write(entry: LogEntry) {\n if (filter && !filter(entry)) return\n logs.push(formatter(entry))\n },\n getLogMessage() {\n return logs.map(toInspectLogEntry)\n .map(log => log.args.join(' '))\n .join('\\n')\n },\n getLogMessageWithLevel() { return toMessageWithLevel(logs) }\n })\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=memory.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.spec.d.ts","sourceRoot":"","sources":["../ts/memory.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,110 @@
1
+ import a from 'assertron';
2
+ import { createMemoryLogReporter, logLevels } from './index.js';
3
+ import { assertSSF, logEntriesToString } from './testUtil.js';
4
+ describe('MemoryLogReporter', () => {
5
+ it('filter is readonly', () => {
6
+ const reporter = createMemoryLogReporter();
7
+ const err = a.throws(() => { reporter.filter = () => true; }, err => /only a getter/.test(err));
8
+ assertSSF(err, __filename);
9
+ });
10
+ describe('unit tests', () => {
11
+ test('log entries are saved in the `logs` property', () => {
12
+ const reporter = createMemoryLogReporter();
13
+ const entry = { id: 'log', level: 1, args: ['some messages'], timestamp: new Date() };
14
+ reporter.write(entry);
15
+ expect(reporter.logs).toEqual([entry]);
16
+ });
17
+ test('can override id', () => {
18
+ const reporter = createMemoryLogReporter({ id: 'custom-id-mem' });
19
+ expect(reporter.id).toBe('custom-id-mem');
20
+ });
21
+ test('can filter', () => {
22
+ const filter = (entry) => entry.id !== 'secret';
23
+ const reporter = createMemoryLogReporter({ filter });
24
+ expect(reporter.filter).toBe(filter);
25
+ reporter.write({ id: 'ok', level: 1, args: ['some messages'], timestamp: new Date() });
26
+ reporter.write({ id: 'secret', level: 1, args: ['some messages'], timestamp: new Date() });
27
+ expect(reporter.logs.length).toBe(1);
28
+ });
29
+ test('formatter can be used to pre-process the log', () => {
30
+ const formatter = (entry) => ({
31
+ ...entry,
32
+ args: entry.args.map(arg => arg === 'secret' ? '<censored>' : arg)
33
+ });
34
+ const reporter = createMemoryLogReporter({ formatter });
35
+ expect(reporter.formatter).toBe(formatter);
36
+ const entry = { id: 'log', level: 1, args: ['a', 'secret', 'b'], timestamp: new Date() };
37
+ reporter.write(entry);
38
+ expect(reporter.logs[0].args[1]).toBe('<censored>');
39
+ });
40
+ describe('getLogMessages()', () => {
41
+ test('empty logs returns empty string', () => {
42
+ const reporter = createMemoryLogReporter();
43
+ expect(reporter.getLogMessage()).toEqual('');
44
+ });
45
+ test('print args', () => {
46
+ const reporter = createMemoryLogReporter();
47
+ const entry = { id: 'log', level: 1, args: ['miku', 'is', 'singing'], timestamp: new Date() };
48
+ reporter.write(entry);
49
+ expect(reporter.getLogMessage()).toEqual('miku is singing');
50
+ });
51
+ test('print object arg', () => {
52
+ const reporter = createMemoryLogReporter();
53
+ const entry = { id: 'log', level: 1, args: [{ 'miku': 'sing' }], timestamp: new Date() };
54
+ reporter.write(entry);
55
+ expect(reporter.getLogMessage()).toEqual("{ miku: 'sing' }");
56
+ });
57
+ });
58
+ describe('getLogMessageWithLevel', () => {
59
+ test('print with level', () => {
60
+ const reporter = createMemoryLogReporter();
61
+ reporter.write({ id: 'log', level: logLevels.info, args: ['msg 1'], timestamp: new Date() });
62
+ reporter.write({ id: 'log', level: logLevels.warn, args: ['msg 2'], timestamp: new Date() });
63
+ expect(reporter.getLogMessageWithLevel()).toEqual(`(INFO) msg 1\n(WARN) msg 2`);
64
+ });
65
+ });
66
+ });
67
+ });
68
+ describe('logEntriesToString()', () => {
69
+ test('convert log entries to string', () => {
70
+ const timestamp = new Date(2019, 6);
71
+ const actual = logEntriesToString([
72
+ { id: 'log', level: logLevels.emergency, args: ['emergency'], timestamp },
73
+ { id: 'log', level: logLevels.critical, args: ['critical'], timestamp },
74
+ { id: 'log', level: logLevels.alert, args: ['alert'], timestamp },
75
+ { id: 'log', level: logLevels.error, args: ['error'], timestamp },
76
+ { id: 'log', level: logLevels.warn, args: ['warn'], timestamp },
77
+ { id: 'log', level: logLevels.notice, args: ['notice'], timestamp },
78
+ { id: 'log', level: logLevels.info, args: ['info'], timestamp },
79
+ { id: 'log', level: logLevels.debug, args: ['debug'], timestamp },
80
+ { id: 'log', level: logLevels.trace, args: ['trace'], timestamp }
81
+ ]);
82
+ const iso = timestamp.toISOString();
83
+ expect(actual).toEqual(`${iso},log,(EMERGENCY),emergency
84
+ ${iso},log,(CRITICAL),critical
85
+ ${iso},log,(ALERT),alert
86
+ ${iso},log,(ERROR),error
87
+ ${iso},log,(WARN),warn
88
+ ${iso},log,(NOTICE),notice
89
+ ${iso},log,(INFO),info
90
+ ${iso},log,(DEBUG),debug
91
+ ${iso},log,(TRACE),trace`);
92
+ });
93
+ test('print out object', () => {
94
+ const timestamp = new Date(2021, 4);
95
+ const actual = logEntriesToString([
96
+ { id: 'log', level: logLevels.info, args: ['a', { a: 1 }], timestamp }
97
+ ]);
98
+ const iso = timestamp.toISOString();
99
+ expect(actual).toEqual(`${iso},log,(INFO),a,{ a: 1 }`);
100
+ });
101
+ test('print out array', () => {
102
+ const timestamp = new Date(2021, 4);
103
+ const actual = logEntriesToString([
104
+ { id: 'log', level: logLevels.info, args: ['a', [1, 2, 3]], timestamp }
105
+ ]);
106
+ const iso = timestamp.toISOString();
107
+ expect(actual).toEqual(`${iso},log,(INFO),a,[ 1, 2, 3 ]`);
108
+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AA","sourcesContent":["import a from 'assertron'\nimport { createMemoryLogReporter, LogEntry, LogFilter, LogFormatter, logLevels } from './index.js'\nimport { assertSSF, logEntriesToString } from './testUtil.js'\n\ndescribe('MemoryLogReporter', () => {\n it('filter is readonly', () => {\n const reporter = createMemoryLogReporter()\n const err = a.throws(() => { (reporter as any).filter = () => true }, err => /only a getter/.test(err))\n\n assertSSF(err, __filename)\n })\n\n describe('unit tests', () => {\n test('log entries are saved in the `logs` property', () => {\n const reporter = createMemoryLogReporter()\n const entry = { id: 'log', level: 1, args: ['some messages'], timestamp: new Date() }\n reporter.write(entry)\n expect(reporter.logs).toEqual([entry])\n })\n\n test('can override id', () => {\n const reporter = createMemoryLogReporter({ id: 'custom-id-mem' })\n expect(reporter.id).toBe('custom-id-mem')\n })\n\n test('can filter', () => {\n const filter: LogFilter = (entry) => entry.id !== 'secret'\n const reporter = createMemoryLogReporter({ filter })\n expect(reporter.filter).toBe(filter)\n reporter.write({ id: 'ok', level: 1, args: ['some messages'], timestamp: new Date() })\n reporter.write({ id: 'secret', level: 1, args: ['some messages'], timestamp: new Date() })\n expect(reporter.logs.length).toBe(1)\n })\n\n test('formatter can be used to pre-process the log', () => {\n const formatter: LogFormatter<LogEntry> = (entry) => ({\n ...entry,\n args: entry.args.map(arg => arg === 'secret' ? '<censored>' : arg)\n })\n const reporter = createMemoryLogReporter({ formatter })\n expect(reporter.formatter).toBe(formatter)\n\n const entry = { id: 'log', level: 1, args: ['a', 'secret', 'b'], timestamp: new Date() }\n reporter.write(entry)\n\n expect(reporter.logs[0].args[1]).toBe('<censored>')\n })\n\n describe('getLogMessages()', () => {\n test('empty logs returns empty string', () => {\n const reporter = createMemoryLogReporter()\n\n expect(reporter.getLogMessage()).toEqual('')\n })\n\n test('print args', () => {\n const reporter = createMemoryLogReporter()\n const entry = { id: 'log', level: 1, args: ['miku', 'is', 'singing'], timestamp: new Date() }\n reporter.write(entry)\n expect(reporter.getLogMessage()).toEqual('miku is singing')\n })\n\n test('print object arg', () => {\n const reporter = createMemoryLogReporter()\n const entry = { id: 'log', level: 1, args: [{ 'miku': 'sing' }], timestamp: new Date() }\n reporter.write(entry)\n expect(reporter.getLogMessage()).toEqual(\"{ miku: 'sing' }\")\n })\n })\n\n describe('getLogMessageWithLevel', () => {\n test('print with level', () => {\n const reporter = createMemoryLogReporter()\n reporter.write({ id: 'log', level: logLevels.info, args: ['msg 1'], timestamp: new Date() })\n reporter.write({ id: 'log', level: logLevels.warn, args: ['msg 2'], timestamp: new Date() })\n expect(reporter.getLogMessageWithLevel()).toEqual(`(INFO) msg 1\\n(WARN) msg 2`)\n })\n })\n })\n})\n\ndescribe('logEntriesToString()', () => {\n test('convert log entries to string', () => {\n const timestamp = new Date(2019, 6)\n const actual = logEntriesToString([\n { id: 'log', level: logLevels.emergency, args: ['emergency'], timestamp },\n { id: 'log', level: logLevels.critical, args: ['critical'], timestamp },\n { id: 'log', level: logLevels.alert, args: ['alert'], timestamp },\n { id: 'log', level: logLevels.error, args: ['error'], timestamp },\n { id: 'log', level: logLevels.warn, args: ['warn'], timestamp },\n { id: 'log', level: logLevels.notice, args: ['notice'], timestamp },\n { id: 'log', level: logLevels.info, args: ['info'], timestamp },\n { id: 'log', level: logLevels.debug, args: ['debug'], timestamp },\n { id: 'log', level: logLevels.trace, args: ['trace'], timestamp }\n ])\n\n const iso = timestamp.toISOString()\n expect(actual).toEqual(`${iso},log,(EMERGENCY),emergency\n${iso},log,(CRITICAL),critical\n${iso},log,(ALERT),alert\n${iso},log,(ERROR),error\n${iso},log,(WARN),warn\n${iso},log,(NOTICE),notice\n${iso},log,(INFO),info\n${iso},log,(DEBUG),debug\n${iso},log,(TRACE),trace`)\n })\n\n test('print out object', () => {\n const timestamp = new Date(2021, 4)\n const actual = logEntriesToString([\n { id: 'log', level: logLevels.info, args: ['a', { a: 1 }], timestamp }\n ])\n\n const iso = timestamp.toISOString()\n expect(actual).toEqual(`${iso},log,(INFO),a,{ a: 1 }`)\n })\n\n test('print out array', () => {\n const timestamp = new Date(2021, 4)\n const actual = logEntriesToString([\n { id: 'log', level: logLevels.info, args: ['a', [1, 2, 3]], timestamp }\n ])\n\n const iso = timestamp.toISOString()\n expect(actual).toEqual(`${iso},log,(INFO),a,[ 1, 2, 3 ]`)\n })\n})\n"]}
@@ -0,0 +1,7 @@
1
+ import type { ConsoleLike, LogEntry } from './types.js';
2
+ export declare const toInspectLogEntry: (e: LogEntry) => LogEntry;
3
+ export declare function isConsoleDebugAvailable(): boolean;
4
+ export declare const polyfill: {
5
+ console?: ConsoleLike;
6
+ };
7
+ //# sourceMappingURL=platform.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.browser.d.ts","sourceRoot":"","sources":["../ts/platform.browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEvD,eAAO,MAAM,iBAAiB,MAAO,QAAQ,aAAM,CAAA;AACnD,wBAAgB,uBAAuB,YAEtC;AAED,eAAO,MAAM,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAA;CAAO,CAAA"}
@@ -0,0 +1,6 @@
1
+ export const toInspectLogEntry = (e) => e;
2
+ export function isConsoleDebugAvailable() {
3
+ return true;
4
+ }
5
+ export const polyfill = {};
6
+ //# sourceMappingURL=platform.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.browser.js","sourceRoot":"","sources":["../ts/platform.browser.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAA;AACnD,MAAM,UAAU,uBAAuB;IACrC,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAA8B,EAAE,CAAA","sourcesContent":["import type { ConsoleLike, LogEntry } from './types.js'\n\nexport const toInspectLogEntry = (e: LogEntry) => e\nexport function isConsoleDebugAvailable() {\n return true\n}\n\nexport const polyfill: { console?: ConsoleLike } = {}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { ConsoleLike, LogEntry } from './types.js';
2
+ export declare function semverGt(versionString: string, version: [number, number, number]): boolean;
3
+ export declare function isConsoleDebugAvailable(): boolean;
4
+ export declare const toInspectLogEntry: (e: LogEntry) => LogEntry;
5
+ export declare const polyfill: {
6
+ console?: ConsoleLike;
7
+ };
8
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEvD,wBAAgB,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,WAOhF;AAGD,wBAAgB,uBAAuB,YAKtC;AAED,eAAO,MAAM,iBAAiB,MAAO,QAAQ,aAEzC,CAAA;AAEJ,eAAO,MAAM,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAA;CAAO,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { inspect } from 'util';
2
+ export function semverGt(versionString, version) {
3
+ const actual = versionString.split('.').reverse().reduce((p, v, i) => {
4
+ p += Number.parseInt(v, 10) * Math.pow(100, i);
5
+ return p;
6
+ }, 0);
7
+ return actual > (version[0] * 10000 + version[1] * 100 + version[2]);
8
+ }
9
+ // istanbul ignore next
10
+ export function isConsoleDebugAvailable() {
11
+ // without this, systemJs will complain `process is not defined`
12
+ if (!global.process)
13
+ return true;
14
+ const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version;
15
+ return semverGt(versionString, [9, 3, 0]);
16
+ }
17
+ export const toInspectLogEntry = (e) => (e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),
18
+ e);
19
+ export const polyfill = {};
20
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
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K,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClG,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,QAAQ,GAA8B,EAAE,CAAA","sourcesContent":["import { inspect } from 'util'\nimport type { ConsoleLike, LogEntry } from './types.js'\n\nexport function semverGt(versionString: string, version: [number, number, number]) {\n const actual = versionString.split('.').reverse().reduce((p, v, i) => {\n p += Number.parseInt(v, 10) * Math.pow(100, i)\n return p\n }, 0)\n\n return actual > (version[0] * 10000 + version[1] * 100 + version[2])\n}\n\n// istanbul ignore next\nexport function isConsoleDebugAvailable() {\n // without this, systemJs will complain `process is not defined`\n if (!global.process) return true\n const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version\n return semverGt(versionString, [9, 3, 0])\n}\n\nexport const toInspectLogEntry = (e: LogEntry) => (\n e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),\n e)\n\nexport const polyfill: { console?: ConsoleLike } = {}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=platform.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.spec.d.ts","sourceRoot":"","sources":["../ts/platform.spec.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- import { semverGt } from './semverGt.js';
1
+ import { semverGt } from './platform.js';
2
2
  test('9.3.0 returns false', () => {
3
3
  expect(semverGt('9.3.0', [9, 3, 0])).toBe(false);
4
4
  });
@@ -17,4 +17,4 @@ test('9.10.0 returns true', () => {
17
17
  test('10.0.0 returns true', () => {
18
18
  expect(semverGt('10.0.0', [9, 3, 0])).toBe(true);
19
19
  });
20
- //# sourceMappingURL=semverGt.spec.js.map
20
+ //# sourceMappingURL=platform.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.spec.js","sourceRoot":"","sources":["../ts/platform.spec.ts"],"names":[],"mappings":"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AI,CAAC,CAAA;AAClD,CAAC,CAAC,CAAA","sourcesContent":["import { semverGt } from './platform.js'\n\ntest('9.3.0 returns false', () => {\n expect(semverGt('9.3.0', [9, 3, 0])).toBe(false)\n})\n\ntest('9.3.1 returns true', () => {\n expect(semverGt('9.3.1', [9, 3, 0])).toBe(true)\n})\n\ntest('9.3.1 returns true', () => {\n expect(semverGt('9.3.1', [9, 3, 0])).toBe(true)\n})\n\ntest('9.4.0 returns true', () => {\n expect(semverGt('9.4.0', [9, 3, 0])).toBe(true)\n})\n\ntest('9.10.0 returns true', () => {\n expect(semverGt('9.10.0', [9, 3, 0])).toBe(true)\n})\n\ntest('10.0.0 returns true', () => {\n expect(semverGt('10.0.0', [9, 3, 0])).toBe(true)\n})\n"]}
@@ -0,0 +1,21 @@
1
+ import { StackTraceMeta } from '@just-func/types';
2
+ import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js';
3
+ export interface StandardLog<N extends string = LogMethodNames> {
4
+ readonly logLevel: number;
5
+ toLogLevelName(level: number): string;
6
+ toLogLevel(name: N): number;
7
+ getLogger(params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N | LogMethodNames>;
8
+ }
9
+ export declare function createStandardLog<N extends string = LogMethodNames>(options?: Partial<StandardLogOptions<N>>, _meta?: StackTraceMeta): Readonly<StandardLog<N>>;
10
+ export declare function createStandardLogForTest(logLevel?: LogLevel): {
11
+ reporter: import("./memory.js").MemoryLogReporter;
12
+ logLevel: number;
13
+ toLogLevelName: (level: number) => string;
14
+ toLogLevel: (name: LogMethodNames) => number;
15
+ getLogger: (params: [id: string, options?: LoggerOptions | undefined], meta?: StackTraceMeta | undefined) => Logger<LogMethodNames>;
16
+ };
17
+ /**
18
+ * Suppress logging within the code block.
19
+ */
20
+ export declare function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R;
21
+ //# sourceMappingURL=standardLog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standardLog.d.ts","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAMjD,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAErG,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACtC,UAAU,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;IAC5B,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,EAAE,IAAI,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC,CAAC,GAAG,cAAc,CAAC,CAAA;CAC5G;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACjE,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,cAAc,GAC/D,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAkB1B;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,GAAE,QAA0B;;;;;;EAI5E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA"}
@@ -0,0 +1,36 @@
1
+ import { required } from 'type-plus';
2
+ import { createLogger } from './logger.js';
3
+ import { logLevels } from './logLevels.js';
4
+ import { createLogStore } from './logStore.js';
5
+ import { createMemoryLogReporter } from './memory.js';
6
+ export function createStandardLog(options, _meta) {
7
+ const store = createLogStore(required({ logLevel: logLevels.info }, options));
8
+ return Object.freeze({
9
+ get logLevel() { return store.logLevel; },
10
+ toLogLevelName(level) {
11
+ return store.logLevelStore.getName(level);
12
+ },
13
+ toLogLevel(name) {
14
+ return store.logLevelStore.getLevel(name);
15
+ },
16
+ getLogger([id, options], meta) {
17
+ if (store.loggers[id])
18
+ return store.loggers[id];
19
+ const opt = required({ level: store.logLevel }, options);
20
+ return store.loggers[id] = createLogger([store, id, opt], { ssf: this.getLogger, ...meta });
21
+ }
22
+ });
23
+ }
24
+ export function createStandardLogForTest(logLevel = logLevels.debug) {
25
+ const reporter = createMemoryLogReporter();
26
+ const standardLog = createStandardLog({ reporters: [reporter], logLevel });
27
+ return { ...standardLog, reporter };
28
+ }
29
+ export function suppressLogs(block, ...logs) {
30
+ const origLevels = logs.map(l => l.level);
31
+ logs.forEach(l => l.level = logLevels.none);
32
+ const result = block();
33
+ logs.forEach((l, i) => l.level = origLevels[i]);
34
+ return result;
35
+ }
36
+ //# sourceMappingURL=standardLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAUrD,MAAM,UAAU,iBAAiB,CAC/B,OAAwC,EAAE,KAAsB;IAEhE,MAAM,KAAK,GAAG,cAAc,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;IAE7E,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,QAAQ,KAAK,OAAO,KAAK,CAAC,QAAQ,CAAA,CAAC,C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S,CAAC,IAAI,CAAC,CAAA;IAC3C,MAAM,MAAM,GAAG,KAAK,EAAE,CAAA;IACtB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/C,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { StackTraceMeta } from '@just-func/types'\nimport { required } from 'type-plus'\nimport { createLogger } from './logger.js'\nimport { logLevels } from './logLevels.js'\nimport { createLogStore } from './logStore.js'\nimport { createMemoryLogReporter } from './memory.js'\nimport type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js'\n\nexport interface StandardLog<N extends string = LogMethodNames> {\n readonly logLevel: number,\n toLogLevelName(level: number): string,\n toLogLevel(name: N): number,\n getLogger(params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N | LogMethodNames>\n}\n\nexport function createStandardLog<N extends string = LogMethodNames>(\n options?: Partial<StandardLogOptions<N>>, _meta?: StackTraceMeta\n): Readonly<StandardLog<N>> {\n const store = createLogStore(required({ logLevel: logLevels.info }, options))\n\n return Object.freeze({\n get logLevel() { return store.logLevel },\n\n toLogLevelName(level: number) {\n return store.logLevelStore.getName(level)\n },\n toLogLevel(name: string) {\n return store.logLevelStore.getLevel(name)\n },\n getLogger([id, options]: [id: string, options?: LoggerOptions], meta?: StackTraceMeta) {\n if (store.loggers[id]) return store.loggers[id] as any\n const opt = required({ level: store.logLevel }, options)\n return store.loggers[id] = createLogger([store, id, opt], { ssf: this.getLogger, ...meta }) as any\n }\n })\n}\n\nexport function createStandardLogForTest(logLevel: LogLevel = logLevels.debug) {\n const reporter = createMemoryLogReporter()\n const standardLog = createStandardLog({ reporters: [reporter], logLevel })\n return { ...standardLog, reporter }\n}\n\n/**\n * Suppress logging within the code block.\n */\nexport function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R\nexport function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {\n const origLevels = logs.map(l => l.level)\n logs.forEach(l => l.level = logLevels.none)\n const result = block()\n logs.forEach((l, i) => l.level = origLevels[i])\n return result\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=standardLog.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standardLog.spec.d.ts","sourceRoot":"","sources":["../ts/standardLog.spec.ts"],"names":[],"mappings":""}