standard-log 7.1.0 → 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 (551) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +57 -133
  3. package/{libm/console/createConsoleLogReporter.d.ts → cjs/console.d.ts} +5 -5
  4. package/cjs/console.d.ts.map +1 -0
  5. package/cjs/console.js +76 -0
  6. package/cjs/console.js.map +1 -0
  7. package/cjs/console.spec.d.ts +2 -0
  8. package/cjs/console.spec.d.ts.map +1 -0
  9. package/cjs/console.spec.js +177 -0
  10. package/cjs/console.spec.js.map +1 -0
  11. package/cjs/errors.d.ts +9 -0
  12. package/cjs/errors.d.ts.map +1 -0
  13. package/cjs/errors.js +43 -0
  14. package/cjs/errors.js.map +1 -0
  15. package/cjs/formatter.d.ts +6 -0
  16. package/cjs/formatter.d.ts.map +1 -0
  17. package/cjs/formatter.js +46 -0
  18. package/cjs/formatter.js.map +1 -0
  19. package/cjs/formatter.spec.d.ts +2 -0
  20. package/cjs/formatter.spec.d.ts.map +1 -0
  21. package/cjs/formatter.spec.js +32 -0
  22. package/cjs/formatter.spec.js.map +1 -0
  23. package/cjs/index.d.ts +8 -0
  24. package/cjs/index.d.ts.map +1 -0
  25. package/cjs/index.js +24 -0
  26. package/cjs/index.js.map +1 -0
  27. package/cjs/logLevels.d.ts +60 -0
  28. package/cjs/logLevels.d.ts.map +1 -0
  29. package/cjs/logLevels.js +87 -0
  30. package/cjs/logLevels.js.map +1 -0
  31. package/cjs/logStore.d.ts +20 -0
  32. package/cjs/logStore.d.ts.map +1 -0
  33. package/cjs/logStore.js +44 -0
  34. package/cjs/logStore.js.map +1 -0
  35. package/cjs/logStore.spec.d.ts +2 -0
  36. package/cjs/logStore.spec.d.ts.map +1 -0
  37. package/cjs/logStore.spec.js +93 -0
  38. package/cjs/logStore.spec.js.map +1 -0
  39. package/cjs/logger.d.ts +6 -0
  40. package/cjs/logger.d.ts.map +1 -0
  41. package/cjs/logger.js +97 -0
  42. package/cjs/logger.js.map +1 -0
  43. package/{lib/memory/MemoryLogReporter.d.ts → cjs/memory.d.ts} +2 -2
  44. package/cjs/memory.d.ts.map +1 -0
  45. package/cjs/memory.js +39 -0
  46. package/cjs/memory.js.map +1 -0
  47. package/cjs/memory.spec.d.ts +2 -0
  48. package/cjs/memory.spec.d.ts.map +1 -0
  49. package/cjs/memory.spec.js +115 -0
  50. package/cjs/memory.spec.js.map +1 -0
  51. package/cjs/package.json +1 -0
  52. package/cjs/platform.browser.d.ts +7 -0
  53. package/cjs/platform.browser.d.ts.map +1 -0
  54. package/cjs/platform.browser.js +11 -0
  55. package/cjs/platform.browser.js.map +1 -0
  56. package/cjs/platform.d.ts +8 -0
  57. package/cjs/platform.d.ts.map +1 -0
  58. package/cjs/platform.js +26 -0
  59. package/cjs/platform.js.map +1 -0
  60. package/cjs/platform.spec.d.ts +2 -0
  61. package/cjs/platform.spec.d.ts.map +1 -0
  62. package/cjs/platform.spec.js +22 -0
  63. package/cjs/platform.spec.js.map +1 -0
  64. package/cjs/standardLog.d.ts +21 -0
  65. package/cjs/standardLog.d.ts.map +1 -0
  66. package/cjs/standardLog.js +59 -0
  67. package/cjs/standardLog.js.map +1 -0
  68. package/cjs/standardLog.spec.d.ts +2 -0
  69. package/cjs/standardLog.spec.d.ts.map +1 -0
  70. package/cjs/standardLog.spec.js +536 -0
  71. package/cjs/standardLog.spec.js.map +1 -0
  72. package/cjs/testUtil.d.ts +10 -0
  73. package/cjs/testUtil.d.ts.map +1 -0
  74. package/cjs/testUtil.js +28 -0
  75. package/cjs/testUtil.js.map +1 -0
  76. package/{lib → cjs}/types.d.ts +33 -24
  77. package/cjs/types.d.ts.map +1 -0
  78. package/{lib/console → cjs}/types.js +0 -0
  79. package/cjs/types.js.map +1 -0
  80. package/cjs/types.spec.d.ts +2 -0
  81. package/cjs/types.spec.d.ts.map +1 -0
  82. package/cjs/types.spec.js +7 -0
  83. package/cjs/types.spec.js.map +1 -0
  84. package/dist/standard-log.es5.js +1971 -0
  85. package/dist/standard-log.es5.js.gz +0 -0
  86. package/dist/standard-log.es5.js.map +1 -0
  87. package/dist/standard-log.es5.js.map.gz +0 -0
  88. package/dist/standard-log.esm.js +1887 -0
  89. package/dist/standard-log.esm.js.gz +0 -0
  90. package/dist/standard-log.esm.js.map +1 -0
  91. package/dist/standard-log.esm.js.map.gz +0 -0
  92. package/{lib/console/createConsoleLogReporter.d.ts → esm/console.d.ts} +5 -5
  93. package/esm/console.d.ts.map +1 -0
  94. package/{libm/console/polyfilledConsole.js → esm/console.js} +36 -4
  95. package/esm/console.js.map +1 -0
  96. package/esm/console.spec.d.ts +2 -0
  97. package/esm/console.spec.d.ts.map +1 -0
  98. package/esm/console.spec.js +151 -0
  99. package/esm/console.spec.js.map +1 -0
  100. package/esm/errors.d.ts +9 -0
  101. package/esm/errors.d.ts.map +1 -0
  102. package/esm/errors.js +18 -0
  103. package/esm/errors.js.map +1 -0
  104. package/esm/formatter.d.ts +6 -0
  105. package/esm/formatter.d.ts.map +1 -0
  106. package/{libm/formatter/createTimestampFormatter.js → esm/formatter.js} +10 -2
  107. package/esm/formatter.js.map +1 -0
  108. package/esm/formatter.spec.d.ts +2 -0
  109. package/esm/formatter.spec.d.ts.map +1 -0
  110. package/esm/formatter.spec.js +30 -0
  111. package/esm/formatter.spec.js.map +1 -0
  112. package/esm/index.d.ts +8 -0
  113. package/esm/index.d.ts.map +1 -0
  114. package/esm/index.js +8 -0
  115. package/esm/index.js.map +1 -0
  116. package/esm/logLevels.d.ts +60 -0
  117. package/esm/logLevels.d.ts.map +1 -0
  118. package/{libm/logLevel.js → esm/logLevels.js} +29 -3
  119. package/esm/logLevels.js.map +1 -0
  120. package/esm/logStore.d.ts +20 -0
  121. package/esm/logStore.d.ts.map +1 -0
  122. package/esm/logStore.js +37 -0
  123. package/esm/logStore.js.map +1 -0
  124. package/esm/logStore.spec.d.ts +2 -0
  125. package/esm/logStore.spec.d.ts.map +1 -0
  126. package/esm/logStore.spec.js +93 -0
  127. package/esm/logStore.spec.js.map +1 -0
  128. package/esm/logger.d.ts +6 -0
  129. package/esm/logger.d.ts.map +1 -0
  130. package/esm/logger.js +74 -0
  131. package/esm/logger.js.map +1 -0
  132. package/{libm/memory/MemoryLogReporter.d.ts → esm/memory.d.ts} +2 -2
  133. package/esm/memory.d.ts.map +1 -0
  134. package/esm/memory.js +34 -0
  135. package/esm/memory.js.map +1 -0
  136. package/esm/memory.spec.d.ts +2 -0
  137. package/esm/memory.spec.d.ts.map +1 -0
  138. package/esm/memory.spec.js +110 -0
  139. package/esm/memory.spec.js.map +1 -0
  140. package/esm/platform.browser.d.ts +7 -0
  141. package/esm/platform.browser.d.ts.map +1 -0
  142. package/esm/platform.browser.js +6 -0
  143. package/esm/platform.browser.js.map +1 -0
  144. package/esm/platform.d.ts +8 -0
  145. package/esm/platform.d.ts.map +1 -0
  146. package/esm/platform.js +20 -0
  147. package/esm/platform.js.map +1 -0
  148. package/esm/platform.spec.d.ts +2 -0
  149. package/esm/platform.spec.d.ts.map +1 -0
  150. package/esm/platform.spec.js +20 -0
  151. package/esm/platform.spec.js.map +1 -0
  152. package/esm/standardLog.d.ts +21 -0
  153. package/esm/standardLog.d.ts.map +1 -0
  154. package/esm/standardLog.js +36 -0
  155. package/esm/standardLog.js.map +1 -0
  156. package/esm/standardLog.spec.d.ts +2 -0
  157. package/esm/standardLog.spec.d.ts.map +1 -0
  158. package/esm/standardLog.spec.js +434 -0
  159. package/esm/standardLog.spec.js.map +1 -0
  160. package/esm/testUtil.d.ts +10 -0
  161. package/esm/testUtil.d.ts.map +1 -0
  162. package/esm/testUtil.js +17 -0
  163. package/esm/testUtil.js.map +1 -0
  164. package/{libm → esm}/types.d.ts +33 -24
  165. package/esm/types.d.ts.map +1 -0
  166. package/{libm/console → esm}/types.js +0 -0
  167. package/esm/types.js.map +1 -0
  168. package/esm/types.spec.d.ts +2 -0
  169. package/esm/types.spec.d.ts.map +1 -0
  170. package/esm/types.spec.js +5 -0
  171. package/esm/types.spec.js.map +1 -0
  172. package/package.json +72 -31
  173. package/ts/console.ts +72 -0
  174. package/ts/errors.ts +12 -0
  175. package/{src/formatter/createTimestampFormatter.ts → ts/formatter.ts} +13 -2
  176. package/ts/index.ts +7 -0
  177. package/{src/logLevel.ts → ts/logLevels.ts} +20 -3
  178. package/ts/logStore.ts +52 -0
  179. package/ts/logger.ts +85 -0
  180. package/ts/memory.ts +47 -0
  181. package/ts/platform.browser.ts +8 -0
  182. package/ts/platform.ts +25 -0
  183. package/ts/standardLog.ts +54 -0
  184. package/{src → ts}/types.ts +39 -30
  185. package/dist/standard-log.js +0 -5472
  186. package/dist/standard-log.js.gz +0 -0
  187. package/dist/standard-log.js.map +0 -1
  188. package/dist/standard-log.js.map.gz +0 -0
  189. package/lib/LogEntry.d.ts +0 -7
  190. package/lib/LogEntry.d.ts.map +0 -1
  191. package/lib/LogEntry.js +0 -3
  192. package/lib/LogEntry.js.map +0 -1
  193. package/lib/captureLogs.d.ts +0 -4
  194. package/lib/captureLogs.d.ts.map +0 -1
  195. package/lib/captureLogs.js +0 -33
  196. package/lib/captureLogs.js.map +0 -1
  197. package/lib/config.d.ts +0 -12
  198. package/lib/config.d.ts.map +0 -1
  199. package/lib/config.js +0 -49
  200. package/lib/config.js.map +0 -1
  201. package/lib/configForTest.d.ts +0 -5
  202. package/lib/configForTest.d.ts.map +0 -1
  203. package/lib/configForTest.js +0 -18
  204. package/lib/configForTest.js.map +0 -1
  205. package/lib/console/createConsoleLogReporter.d.ts.map +0 -1
  206. package/lib/console/createConsoleLogReporter.js +0 -42
  207. package/lib/console/createConsoleLogReporter.js.map +0 -1
  208. package/lib/console/index.d.ts +0 -4
  209. package/lib/console/index.d.ts.map +0 -1
  210. package/lib/console/index.js +0 -7
  211. package/lib/console/index.js.map +0 -1
  212. package/lib/console/isConsoleDebugAvailable.d.ts +0 -2
  213. package/lib/console/isConsoleDebugAvailable.d.ts.map +0 -1
  214. package/lib/console/isConsoleDebugAvailable.js +0 -18
  215. package/lib/console/isConsoleDebugAvailable.js.map +0 -1
  216. package/lib/console/polyfilledConsole.d.ts +0 -7
  217. package/lib/console/polyfilledConsole.d.ts.map +0 -1
  218. package/lib/console/polyfilledConsole.js +0 -41
  219. package/lib/console/polyfilledConsole.js.map +0 -1
  220. package/lib/console/semverGt.d.ts +0 -2
  221. package/lib/console/semverGt.d.ts.map +0 -1
  222. package/lib/console/semverGt.js +0 -13
  223. package/lib/console/semverGt.js.map +0 -1
  224. package/lib/console/toConsoleMethod.d.ts +0 -2
  225. package/lib/console/toConsoleMethod.d.ts.map +0 -1
  226. package/lib/console/toConsoleMethod.js +0 -22
  227. package/lib/console/toConsoleMethod.js.map +0 -1
  228. package/lib/console/types.d.ts +0 -3
  229. package/lib/console/types.d.ts.map +0 -1
  230. package/lib/console/types.js.map +0 -1
  231. package/lib/customLogLevel.d.ts +0 -11
  232. package/lib/customLogLevel.d.ts.map +0 -1
  233. package/lib/customLogLevel.js +0 -38
  234. package/lib/customLogLevel.js.map +0 -1
  235. package/lib/errors.d.ts +0 -19
  236. package/lib/errors.d.ts.map +0 -1
  237. package/lib/errors.js +0 -46
  238. package/lib/errors.js.map +0 -1
  239. package/lib/formatter/createTimestampFormatter.d.ts +0 -3
  240. package/lib/formatter/createTimestampFormatter.d.ts.map +0 -1
  241. package/lib/formatter/createTimestampFormatter.js +0 -24
  242. package/lib/formatter/createTimestampFormatter.js.map +0 -1
  243. package/lib/formatter/formatLogLevel.d.ts +0 -2
  244. package/lib/formatter/formatLogLevel.d.ts.map +0 -1
  245. package/lib/formatter/formatLogLevel.js +0 -10
  246. package/lib/formatter/formatLogLevel.js.map +0 -1
  247. package/lib/formatter/index.d.ts +0 -4
  248. package/lib/formatter/index.d.ts.map +0 -1
  249. package/lib/formatter/index.js +0 -7
  250. package/lib/formatter/index.js.map +0 -1
  251. package/lib/formatter/plainLogFormatter.d.ts +0 -3
  252. package/lib/formatter/plainLogFormatter.d.ts.map +0 -1
  253. package/lib/formatter/plainLogFormatter.js +0 -11
  254. package/lib/formatter/plainLogFormatter.js.map +0 -1
  255. package/lib/getDefaultReporter.browser.d.ts +0 -2
  256. package/lib/getDefaultReporter.browser.d.ts.map +0 -1
  257. package/lib/getDefaultReporter.browser.js +0 -15
  258. package/lib/getDefaultReporter.browser.js.map +0 -1
  259. package/lib/getDefaultReporter.d.ts +0 -2
  260. package/lib/getDefaultReporter.d.ts.map +0 -1
  261. package/lib/getDefaultReporter.js +0 -19
  262. package/lib/getDefaultReporter.js.map +0 -1
  263. package/lib/getLogModeFromEnvironment.browser.d.ts +0 -3
  264. package/lib/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  265. package/lib/getLogModeFromEnvironment.browser.js +0 -9
  266. package/lib/getLogModeFromEnvironment.browser.js.map +0 -1
  267. package/lib/getLogModeFromEnvironment.d.ts +0 -3
  268. package/lib/getLogModeFromEnvironment.d.ts.map +0 -1
  269. package/lib/getLogModeFromEnvironment.js +0 -17
  270. package/lib/getLogModeFromEnvironment.js.map +0 -1
  271. package/lib/getLogger.d.ts +0 -9
  272. package/lib/getLogger.d.ts.map +0 -1
  273. package/lib/getLogger.js +0 -95
  274. package/lib/getLogger.js.map +0 -1
  275. package/lib/getLoggers.d.ts +0 -7
  276. package/lib/getLoggers.d.ts.map +0 -1
  277. package/lib/getLoggers.js +0 -15
  278. package/lib/getLoggers.js.map +0 -1
  279. package/lib/index.d.ts +0 -17
  280. package/lib/index.d.ts.map +0 -1
  281. package/lib/index.js +0 -20
  282. package/lib/index.js.map +0 -1
  283. package/lib/logLevel.d.ts +0 -106
  284. package/lib/logLevel.d.ts.map +0 -1
  285. package/lib/logLevel.js +0 -59
  286. package/lib/logLevel.js.map +0 -1
  287. package/lib/logLevelFn.d.ts +0 -20
  288. package/lib/logLevelFn.d.ts.map +0 -1
  289. package/lib/logLevelFn.js +0 -76
  290. package/lib/logLevelFn.js.map +0 -1
  291. package/lib/logReporter.d.ts +0 -7
  292. package/lib/logReporter.d.ts.map +0 -1
  293. package/lib/logReporter.js +0 -29
  294. package/lib/logReporter.js.map +0 -1
  295. package/lib/logReporterInternal.d.ts +0 -3
  296. package/lib/logReporterInternal.d.ts.map +0 -1
  297. package/lib/logReporterInternal.js +0 -23
  298. package/lib/logReporterInternal.js.map +0 -1
  299. package/lib/memory/MemoryLogReporter.d.ts.map +0 -1
  300. package/lib/memory/MemoryLogReporter.js +0 -56
  301. package/lib/memory/MemoryLogReporter.js.map +0 -1
  302. package/lib/memory/index.d.ts +0 -3
  303. package/lib/memory/index.d.ts.map +0 -1
  304. package/lib/memory/index.js +0 -6
  305. package/lib/memory/index.js.map +0 -1
  306. package/lib/memory/logEntriesToString.d.ts +0 -3
  307. package/lib/memory/logEntriesToString.d.ts.map +0 -1
  308. package/lib/memory/logEntriesToString.js +0 -10
  309. package/lib/memory/logEntriesToString.js.map +0 -1
  310. package/lib/memory/toInspectStringForObject.d.ts +0 -3
  311. package/lib/memory/toInspectStringForObject.d.ts.map +0 -1
  312. package/lib/memory/toInspectStringForObject.js +0 -15
  313. package/lib/memory/toInspectStringForObject.js.map +0 -1
  314. package/lib/shouldLog.d.ts +0 -8
  315. package/lib/shouldLog.d.ts.map +0 -1
  316. package/lib/shouldLog.js +0 -14
  317. package/lib/shouldLog.js.map +0 -1
  318. package/lib/store.d.ts +0 -3
  319. package/lib/store.d.ts.map +0 -1
  320. package/lib/store.js +0 -17
  321. package/lib/store.js.map +0 -1
  322. package/lib/suppressLogs.d.ts +0 -6
  323. package/lib/suppressLogs.d.ts.map +0 -1
  324. package/lib/suppressLogs.js +0 -17
  325. package/lib/suppressLogs.js.map +0 -1
  326. package/lib/testUtil.d.ts +0 -7
  327. package/lib/testUtil.d.ts.map +0 -1
  328. package/lib/testUtil.js +0 -23
  329. package/lib/testUtil.js.map +0 -1
  330. package/lib/types.d.ts.map +0 -1
  331. package/lib/types.js +0 -3
  332. package/lib/types.js.map +0 -1
  333. package/lib/typesInternal.d.ts +0 -20
  334. package/lib/typesInternal.d.ts.map +0 -1
  335. package/lib/typesInternal.js +0 -3
  336. package/lib/typesInternal.js.map +0 -1
  337. package/lib/utils.d.ts +0 -5
  338. package/lib/utils.d.ts.map +0 -1
  339. package/lib/utils.js +0 -14
  340. package/lib/utils.js.map +0 -1
  341. package/lib/writeToReporters.d.ts +0 -6
  342. package/lib/writeToReporters.d.ts.map +0 -1
  343. package/lib/writeToReporters.js +0 -22
  344. package/lib/writeToReporters.js.map +0 -1
  345. package/libm/LogEntry.d.ts +0 -7
  346. package/libm/LogEntry.d.ts.map +0 -1
  347. package/libm/LogEntry.js +0 -2
  348. package/libm/LogEntry.js.map +0 -1
  349. package/libm/captureLogs.d.ts +0 -4
  350. package/libm/captureLogs.d.ts.map +0 -1
  351. package/libm/captureLogs.js +0 -29
  352. package/libm/captureLogs.js.map +0 -1
  353. package/libm/config.d.ts +0 -12
  354. package/libm/config.d.ts.map +0 -1
  355. package/libm/config.js +0 -44
  356. package/libm/config.js.map +0 -1
  357. package/libm/configForTest.d.ts +0 -5
  358. package/libm/configForTest.d.ts.map +0 -1
  359. package/libm/configForTest.js +0 -14
  360. package/libm/configForTest.js.map +0 -1
  361. package/libm/console/createConsoleLogReporter.d.ts.map +0 -1
  362. package/libm/console/createConsoleLogReporter.js +0 -37
  363. package/libm/console/createConsoleLogReporter.js.map +0 -1
  364. package/libm/console/index.d.ts +0 -4
  365. package/libm/console/index.d.ts.map +0 -1
  366. package/libm/console/index.js +0 -4
  367. package/libm/console/index.js.map +0 -1
  368. package/libm/console/isConsoleDebugAvailable.d.ts +0 -2
  369. package/libm/console/isConsoleDebugAvailable.d.ts.map +0 -1
  370. package/libm/console/isConsoleDebugAvailable.js +0 -13
  371. package/libm/console/isConsoleDebugAvailable.js.map +0 -1
  372. package/libm/console/polyfilledConsole.d.ts +0 -7
  373. package/libm/console/polyfilledConsole.d.ts.map +0 -1
  374. package/libm/console/polyfilledConsole.js.map +0 -1
  375. package/libm/console/semverGt.d.ts +0 -2
  376. package/libm/console/semverGt.d.ts.map +0 -1
  377. package/libm/console/semverGt.js +0 -9
  378. package/libm/console/semverGt.js.map +0 -1
  379. package/libm/console/toConsoleMethod.d.ts +0 -2
  380. package/libm/console/toConsoleMethod.d.ts.map +0 -1
  381. package/libm/console/toConsoleMethod.js +0 -18
  382. package/libm/console/toConsoleMethod.js.map +0 -1
  383. package/libm/console/types.d.ts +0 -3
  384. package/libm/console/types.d.ts.map +0 -1
  385. package/libm/console/types.js.map +0 -1
  386. package/libm/customLogLevel.d.ts +0 -11
  387. package/libm/customLogLevel.d.ts.map +0 -1
  388. package/libm/customLogLevel.js +0 -30
  389. package/libm/customLogLevel.js.map +0 -1
  390. package/libm/errors.d.ts +0 -19
  391. package/libm/errors.d.ts.map +0 -1
  392. package/libm/errors.js +0 -32
  393. package/libm/errors.js.map +0 -1
  394. package/libm/formatter/createTimestampFormatter.d.ts +0 -3
  395. package/libm/formatter/createTimestampFormatter.d.ts.map +0 -1
  396. package/libm/formatter/createTimestampFormatter.js.map +0 -1
  397. package/libm/formatter/formatLogLevel.d.ts +0 -2
  398. package/libm/formatter/formatLogLevel.d.ts.map +0 -1
  399. package/libm/formatter/formatLogLevel.js +0 -6
  400. package/libm/formatter/formatLogLevel.js.map +0 -1
  401. package/libm/formatter/index.d.ts +0 -4
  402. package/libm/formatter/index.d.ts.map +0 -1
  403. package/libm/formatter/index.js +0 -4
  404. package/libm/formatter/index.js.map +0 -1
  405. package/libm/formatter/plainLogFormatter.d.ts +0 -3
  406. package/libm/formatter/plainLogFormatter.d.ts.map +0 -1
  407. package/libm/formatter/plainLogFormatter.js +0 -5
  408. package/libm/formatter/plainLogFormatter.js.map +0 -1
  409. package/libm/getDefaultReporter.browser.d.ts +0 -2
  410. package/libm/getDefaultReporter.browser.d.ts.map +0 -1
  411. package/libm/getDefaultReporter.browser.js +0 -11
  412. package/libm/getDefaultReporter.browser.js.map +0 -1
  413. package/libm/getDefaultReporter.d.ts +0 -2
  414. package/libm/getDefaultReporter.d.ts.map +0 -1
  415. package/libm/getDefaultReporter.js +0 -15
  416. package/libm/getDefaultReporter.js.map +0 -1
  417. package/libm/getLogModeFromEnvironment.browser.d.ts +0 -3
  418. package/libm/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  419. package/libm/getLogModeFromEnvironment.browser.js +0 -5
  420. package/libm/getLogModeFromEnvironment.browser.js.map +0 -1
  421. package/libm/getLogModeFromEnvironment.d.ts +0 -3
  422. package/libm/getLogModeFromEnvironment.d.ts.map +0 -1
  423. package/libm/getLogModeFromEnvironment.js +0 -13
  424. package/libm/getLogModeFromEnvironment.js.map +0 -1
  425. package/libm/getLogger.d.ts +0 -9
  426. package/libm/getLogger.d.ts.map +0 -1
  427. package/libm/getLogger.js +0 -78
  428. package/libm/getLogger.js.map +0 -1
  429. package/libm/getLoggers.d.ts +0 -7
  430. package/libm/getLoggers.d.ts.map +0 -1
  431. package/libm/getLoggers.js +0 -11
  432. package/libm/getLoggers.js.map +0 -1
  433. package/libm/index.d.ts +0 -17
  434. package/libm/index.d.ts.map +0 -1
  435. package/libm/index.js +0 -17
  436. package/libm/index.js.map +0 -1
  437. package/libm/logLevel.d.ts +0 -106
  438. package/libm/logLevel.d.ts.map +0 -1
  439. package/libm/logLevel.js.map +0 -1
  440. package/libm/logLevelFn.d.ts +0 -20
  441. package/libm/logLevelFn.d.ts.map +0 -1
  442. package/libm/logLevelFn.js +0 -67
  443. package/libm/logLevelFn.js.map +0 -1
  444. package/libm/logReporter.d.ts +0 -7
  445. package/libm/logReporter.d.ts.map +0 -1
  446. package/libm/logReporter.js +0 -21
  447. package/libm/logReporter.js.map +0 -1
  448. package/libm/logReporterInternal.d.ts +0 -3
  449. package/libm/logReporterInternal.d.ts.map +0 -1
  450. package/libm/logReporterInternal.js +0 -19
  451. package/libm/logReporterInternal.js.map +0 -1
  452. package/libm/memory/MemoryLogReporter.d.ts.map +0 -1
  453. package/libm/memory/MemoryLogReporter.js +0 -51
  454. package/libm/memory/MemoryLogReporter.js.map +0 -1
  455. package/libm/memory/index.d.ts +0 -3
  456. package/libm/memory/index.d.ts.map +0 -1
  457. package/libm/memory/index.js +0 -3
  458. package/libm/memory/index.js.map +0 -1
  459. package/libm/memory/logEntriesToString.d.ts +0 -3
  460. package/libm/memory/logEntriesToString.d.ts.map +0 -1
  461. package/libm/memory/logEntriesToString.js +0 -6
  462. package/libm/memory/logEntriesToString.js.map +0 -1
  463. package/libm/memory/toInspectStringForObject.d.ts +0 -3
  464. package/libm/memory/toInspectStringForObject.d.ts.map +0 -1
  465. package/libm/memory/toInspectStringForObject.js +0 -11
  466. package/libm/memory/toInspectStringForObject.js.map +0 -1
  467. package/libm/shouldLog.d.ts +0 -8
  468. package/libm/shouldLog.d.ts.map +0 -1
  469. package/libm/shouldLog.js +0 -10
  470. package/libm/shouldLog.js.map +0 -1
  471. package/libm/store.d.ts +0 -3
  472. package/libm/store.d.ts.map +0 -1
  473. package/libm/store.js +0 -24
  474. package/libm/store.js.map +0 -1
  475. package/libm/suppressLogs.d.ts +0 -6
  476. package/libm/suppressLogs.d.ts.map +0 -1
  477. package/libm/suppressLogs.js +0 -9
  478. package/libm/suppressLogs.js.map +0 -1
  479. package/libm/testUtil.d.ts +0 -7
  480. package/libm/testUtil.d.ts.map +0 -1
  481. package/libm/testUtil.js +0 -17
  482. package/libm/testUtil.js.map +0 -1
  483. package/libm/types.d.ts.map +0 -1
  484. package/libm/types.js +0 -2
  485. package/libm/types.js.map +0 -1
  486. package/libm/typesInternal.d.ts +0 -20
  487. package/libm/typesInternal.d.ts.map +0 -1
  488. package/libm/typesInternal.js +0 -2
  489. package/libm/typesInternal.js.map +0 -1
  490. package/libm/utils.d.ts +0 -5
  491. package/libm/utils.d.ts.map +0 -1
  492. package/libm/utils.js +0 -10
  493. package/libm/utils.js.map +0 -1
  494. package/libm/writeToReporters.d.ts +0 -6
  495. package/libm/writeToReporters.d.ts.map +0 -1
  496. package/libm/writeToReporters.js +0 -18
  497. package/libm/writeToReporters.js.map +0 -1
  498. package/src/LogEntry.ts +0 -7
  499. package/src/captureLogs.spec.ts +0 -52
  500. package/src/captureLogs.ts +0 -35
  501. package/src/config.spec.ts +0 -80
  502. package/src/config.ts +0 -57
  503. package/src/configForTest.spec.ts +0 -16
  504. package/src/configForTest.ts +0 -16
  505. package/src/console/createConsoleLogReporter.spec.ts +0 -198
  506. package/src/console/createConsoleLogReporter.ts +0 -42
  507. package/src/console/index.ts +0 -3
  508. package/src/console/isConsoleDebugAvailable.ts +0 -11
  509. package/src/console/polyfilledConsole.ts +0 -34
  510. package/src/console/semverGt.spec.ts +0 -25
  511. package/src/console/semverGt.ts +0 -9
  512. package/src/console/toConsoleMethod.ts +0 -18
  513. package/src/console/types.ts +0 -3
  514. package/src/customLogLevel.spec.ts +0 -39
  515. package/src/customLogLevel.ts +0 -35
  516. package/src/errors.ts +0 -24
  517. package/src/formatter/createTimestampFormatter.spec.ts +0 -24
  518. package/src/formatter/formatLogLevel.ts +0 -6
  519. package/src/formatter/index.ts +0 -3
  520. package/src/formatter/plainLogFormatter.spec.ts +0 -8
  521. package/src/formatter/plainLogFormatter.ts +0 -6
  522. package/src/getDefaultReporter.browser.ts +0 -13
  523. package/src/getDefaultReporter.ts +0 -15
  524. package/src/getLogModeFromEnvironment.browser.ts +0 -6
  525. package/src/getLogModeFromEnvironment.spec.ts +0 -16
  526. package/src/getLogModeFromEnvironment.ts +0 -16
  527. package/src/getLogger.spec.ts +0 -460
  528. package/src/getLogger.ts +0 -92
  529. package/src/getLoggers.ts +0 -12
  530. package/src/index.ts +0 -16
  531. package/src/logLevel.spec.ts +0 -161
  532. package/src/logLevelFn.ts +0 -72
  533. package/src/logReporter.spec.ts +0 -99
  534. package/src/logReporter.ts +0 -26
  535. package/src/logReporterInternal.ts +0 -18
  536. package/src/memory/MemoryLogReporter.spec.ts +0 -114
  537. package/src/memory/MemoryLogReporter.ts +0 -66
  538. package/src/memory/index.ts +0 -2
  539. package/src/memory/logEntriesToString.spec.ts +0 -47
  540. package/src/memory/logEntriesToString.ts +0 -7
  541. package/src/memory/toInspectStringForObject.ts +0 -13
  542. package/src/shouldLog.ts +0 -11
  543. package/src/store.ts +0 -25
  544. package/src/suppressLogs.spec.ts +0 -34
  545. package/src/suppressLogs.ts +0 -14
  546. package/src/testUtil.ts +0 -19
  547. package/src/types.spec.ts +0 -7
  548. package/src/typesInternal.ts +0 -21
  549. package/src/utils.ts +0 -9
  550. package/src/writeToReporters.spec.ts +0 -9
  551. package/src/writeToReporters.ts +0 -20
@@ -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
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAG9B,MAAM,UAAU,QAAQ,CAAC,aAAqB,EAAE,OAAiC;IAC/E,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE;QACnE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;QAC9C,OAAO,CAAC,CAAA;IACV,CAAC,EAAE,CAAC,CAAC,CAAA;IAEL,OAAO,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AACtE,CAAC;AAED,uBAAuB;AACvB,MAAM,UAAU,uBAAuB;IACrC,gEAAgE;IAChE,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IAChC,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAA;IAClG,OAAO,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAChD,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,KAAK,KAAK,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":""}
@@ -0,0 +1,20 @@
1
+ import { semverGt } from './platform.js';
2
+ test('9.3.0 returns false', () => {
3
+ expect(semverGt('9.3.0', [9, 3, 0])).toBe(false);
4
+ });
5
+ test('9.3.1 returns true', () => {
6
+ expect(semverGt('9.3.1', [9, 3, 0])).toBe(true);
7
+ });
8
+ test('9.3.1 returns true', () => {
9
+ expect(semverGt('9.3.1', [9, 3, 0])).toBe(true);
10
+ });
11
+ test('9.4.0 returns true', () => {
12
+ expect(semverGt('9.4.0', [9, 3, 0])).toBe(true);
13
+ });
14
+ test('9.10.0 returns true', () => {
15
+ expect(semverGt('9.10.0', [9, 3, 0])).toBe(true);
16
+ });
17
+ test('10.0.0 returns true', () => {
18
+ expect(semverGt('10.0.0', [9, 3, 0])).toBe(true);
19
+ });
20
+ //# sourceMappingURL=platform.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.spec.js","sourceRoot":"","sources":["../ts/platform.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC/B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAClD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAC9B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACjD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAC9B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACjD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAC9B,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACjD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC/B,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAClD,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC/B,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,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>;
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,CAAC,CAAA;CAC3F;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,CAAC;QAExC,cAAc,CAAC,KAAa;YAC1B,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC3C,CAAC;QACD,UAAU,CAAC,IAAY;YACrB,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC3C,CAAC;QACD,SAAS,CAAC,CAAC,EAAE,EAAE,OAAO,CAAwC,EAAE,IAAqB;YACnF,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBAAE,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAQ,CAAA;YACtD,MAAM,GAAG,GAAG,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAA;YACxD,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,EAAE,CAAQ,CAAA;QACpG,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,WAAqB,SAAS,CAAC,KAAK;IAC3E,MAAM,QAAQ,GAAG,uBAAuB,EAAE,CAAA;IAC1C,MAAM,WAAW,GAAG,iBAAiB,CAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1E,OAAO,EAAE,GAAG,WAAW,EAAE,QAAQ,EAAE,CAAA;AACrC,CAAC;AAMD,MAAM,UAAU,YAAY,CAAI,KAAc,EAAE,GAAG,IAAc;IAC/D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS,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>\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): Logger<N> {\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":""}
@@ -0,0 +1,434 @@
1
+ import { assertron as a } from 'assertron';
2
+ import { InvalidId } from './errors.js';
3
+ import { logLevels, toLogLevelName } from './logLevels.js';
4
+ import { createMemoryLogReporter } from './memory.js';
5
+ import { createStandardLog, createStandardLogForTest, suppressLogs } from './standardLog.js';
6
+ import { assertSSF, wrapTest } from './testUtil.js';
7
+ describe('createStandardLog()', () => {
8
+ describe('logLevel', () => {
9
+ it('is default to info', () => {
10
+ const actual = createStandardLog();
11
+ expect(actual.logLevel).toBe(logLevels.info);
12
+ });
13
+ it('is readonly', () => {
14
+ const actual = createStandardLog();
15
+ a.throws(() => actual.logLevel = logLevels.planck, err => /only a getter/.test(err));
16
+ });
17
+ it('set logLevel from options', () => {
18
+ const actual = createStandardLog({ logLevel: logLevels.planck });
19
+ expect(actual.logLevel).toBe(logLevels.planck);
20
+ });
21
+ });
22
+ describe('custom levels', () => {
23
+ it('can define custom levels', () => {
24
+ const actual = createStandardLog({ customLevels: { urgent: 80 } });
25
+ expect(actual.toLogLevelName(80)).toBe('urgent');
26
+ });
27
+ });
28
+ describe('reporters', () => {
29
+ it('can specify reporter', () => {
30
+ const mem = createMemoryLogReporter();
31
+ const sl = createStandardLog({ reporters: [mem] });
32
+ const log = sl.getLogger(['x']);
33
+ log.info('abc');
34
+ expect(mem.logs.length).toBe(1);
35
+ });
36
+ });
37
+ });
38
+ describe('createStandardLogForTest()', () => {
39
+ it('returns with memory reporter', () => {
40
+ const { reporter } = createStandardLogForTest();
41
+ expect(reporter.getLogMessageWithLevel()).toBe('');
42
+ });
43
+ it('defaults to debug', () => {
44
+ const store = createStandardLogForTest();
45
+ expect(store.logLevel).toBe(logLevels.debug);
46
+ });
47
+ });
48
+ describe('getLogger()', () => {
49
+ it('supports id with alphanumeric and :_-.', () => {
50
+ const sl = createStandardLog();
51
+ sl.getLogger(['abcdefghijklmnopqrstuvwxyz:-_.1234567890']);
52
+ });
53
+ it('supports id with unicode', () => {
54
+ const sl = createStandardLog();
55
+ sl.getLogger(['ミク香港']);
56
+ });
57
+ it('supports id with @, \\ and /', () => {
58
+ const sl = createStandardLog();
59
+ sl.getLogger(['@unional/fixture']);
60
+ sl.getLogger([`a\\b\\c`]);
61
+ });
62
+ it.each('`~!#$%^&*()=+|[]{}<>,?'.split(''))('throws if id has unsupported character %s', (char) => {
63
+ const sl = createStandardLog();
64
+ a.throws(() => sl.getLogger([char]), InvalidId);
65
+ });
66
+ it('throw InvalidId with ssf to the call site', () => {
67
+ const sl = createStandardLog();
68
+ const err = a.throws(() => sl.getLogger(['!']), InvalidId);
69
+ assertSSF(err, __filename);
70
+ });
71
+ test('id is readonly', () => {
72
+ const sl = createStandardLog();
73
+ const log = sl.getLogger(['id is readonly']);
74
+ a.throws(() => log.id = 'b');
75
+ });
76
+ test('get logger with same name gets the same instance', () => {
77
+ const sl = createStandardLog();
78
+ const expected = sl.getLogger(['same-inst']);
79
+ const actual = sl.getLogger(['same-inst']);
80
+ expect(actual).toBe(expected);
81
+ });
82
+ it('can specify local log level', () => {
83
+ const sl = createStandardLog();
84
+ const log = sl.getLogger(['local', { level: logLevels.trace }]);
85
+ expect(log.level).toBe(logLevels.trace);
86
+ });
87
+ test('new logger will get custom level', () => {
88
+ const sl = createStandardLog({ customLevels: { 'to_logger': 1234 } });
89
+ const actual = sl.getLogger(['to_logger_logger']);
90
+ expect(typeof actual.to_logger).toBe('function');
91
+ });
92
+ describe('log levels', () => {
93
+ async function assertLoggedAtLevel(sl, method, level) {
94
+ const log = sl.getLogger([method]);
95
+ const msg = `should log on level: ${level}`;
96
+ log[method](msg);
97
+ a.satisfies(sl.reporter.logs, [{ id: method, level: sl.toLogLevel(method), args: [msg] }]);
98
+ }
99
+ async function assertNotLoggedAtLevel(sl, method, level) {
100
+ const log = sl.getLogger([method]);
101
+ log[method](`should not log on level: ${level}`);
102
+ expect(sl.reporter.logs.length).toBe(0);
103
+ }
104
+ async function assertLoggedAtLocalLevel(sl, method, localLevel) {
105
+ const log = sl.getLogger([method, { level: localLevel }]);
106
+ const msg = `should log on level: ${localLevel}`;
107
+ log[method](msg);
108
+ a.satisfies(sl.reporter.logs, [{ id: log.id, level: sl.toLogLevel(method), args: [msg] }]);
109
+ }
110
+ async function assertNotLoggedAtLocalLevel(sl, method, localLevel) {
111
+ const log = sl.getLogger([method, { level: localLevel }]);
112
+ log[method](`should not log on level: ${localLevel}`);
113
+ expect(sl.reporter.logs.length).toBe(0);
114
+ }
115
+ async function assertLoggedAtCallLevel(sl, method, callLevel) {
116
+ const log = sl.getLogger([method]);
117
+ let actual = false;
118
+ log.on(callLevel, () => actual = true);
119
+ expect(actual).toBe(true);
120
+ }
121
+ async function assertNotLoggedAtCallLevel(sl, method, callLevel, actualLevel) {
122
+ const log = sl.getLogger([method]);
123
+ log.on(callLevel, () => { throw new Error(`should not log at level ${actualLevel}`); });
124
+ }
125
+ async function assertLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel) {
126
+ const log = sl.getLogger([method, { level: localLevel }]);
127
+ let actual = false;
128
+ log.on(callLevel, () => actual = true);
129
+ expect(actual).toBe(true);
130
+ }
131
+ async function assertNotLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel) {
132
+ const log = sl.getLogger([method, { level: localLevel }]);
133
+ log.on(callLevel, () => { throw new Error(`should not log at level ${localLevel}`); });
134
+ }
135
+ const shouldLog = wrapTest((test) => (method, level) => {
136
+ const sl = createStandardLogForTest(level);
137
+ const name = sl.toLogLevelName(level);
138
+ test(`${method}() should log on level: ${name} (${level})`, () => {
139
+ return assertLoggedAtLevel(sl, method, level);
140
+ });
141
+ });
142
+ const shouldNotLog = wrapTest((test) => (method, level) => {
143
+ const sl = createStandardLogForTest(level);
144
+ const name = sl.toLogLevelName(level);
145
+ test(`${method}() should not log on level: ${name} (${level})`, () => {
146
+ return assertNotLoggedAtLevel(sl, method, level);
147
+ });
148
+ });
149
+ const shouldLogWithLocalLevelOverride = wrapTest((test) => (method, localLevel) => {
150
+ const localName = toLogLevelName(localLevel);
151
+ [logLevels.none, logLevels.error, logLevels.warn, logLevels.info, logLevels.debug].forEach(globalLevel => {
152
+ const globalName = toLogLevelName(globalLevel) || 'none';
153
+ test(`${method}() should log on local level: ${localName} (${localLevel}) while global level: ${globalName} (${globalLevel})`, () => {
154
+ const sl = createStandardLogForTest(globalLevel);
155
+ return assertLoggedAtLocalLevel(sl, method, localLevel);
156
+ });
157
+ });
158
+ });
159
+ const shouldNotLogWithLocalLevelOverride = wrapTest((test) => (method, localLevel) => {
160
+ const localName = toLogLevelName(localLevel);
161
+ [logLevels.none, logLevels.error, logLevels.warn, logLevels.info, logLevels.debug].forEach(globalLevel => {
162
+ const globalName = toLogLevelName(globalLevel) || 'none';
163
+ test(`${method}() should not log on local level: ${localName} (${localLevel}) while global level: ${globalName} (${globalLevel})`, () => {
164
+ const sl = createStandardLogForTest(globalLevel);
165
+ return assertNotLoggedAtLocalLevel(sl, method, localLevel);
166
+ });
167
+ });
168
+ });
169
+ const shouldCallLogFunction = wrapTest((test) => (callLevel, actualLevel) => {
170
+ const method = toLogLevelName(callLevel);
171
+ const name = toLogLevelName(actualLevel);
172
+ test(`${method}() should call log function on level: ${name} (${actualLevel})`, () => {
173
+ const sl = createStandardLogForTest(actualLevel);
174
+ return assertLoggedAtCallLevel(sl, method, callLevel);
175
+ });
176
+ });
177
+ const shouldNotCallLogFunction = wrapTest((test) => (callLevel, actualLevel) => {
178
+ const method = toLogLevelName(callLevel);
179
+ const name = toLogLevelName(actualLevel);
180
+ test(`${method}() should not call log function on level: ${name} (${actualLevel})`, () => {
181
+ const sl = createStandardLogForTest(actualLevel);
182
+ return assertNotLoggedAtCallLevel(sl, method, callLevel, actualLevel);
183
+ });
184
+ });
185
+ const shouldCallLogFunctionWithLocalLevelOverride = wrapTest((test) => (callLevel, localLevel) => {
186
+ const method = toLogLevelName(callLevel);
187
+ const localName = toLogLevelName(localLevel);
188
+ [logLevels.none, logLevels.error, logLevels.warn, logLevels.info, logLevels.debug].forEach(globalLevel => {
189
+ const globalName = toLogLevelName(globalLevel) || 'none';
190
+ test(`${method}() should log on local level: ${localName} (${localLevel}) while global level: ${globalName} (${globalLevel})`, () => {
191
+ const sl = createStandardLogForTest(globalLevel);
192
+ return assertLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel);
193
+ });
194
+ });
195
+ });
196
+ const shouldNotCallLogFunctionWithLocalLevelOverride = wrapTest((test) => (callLevel, localLevel) => {
197
+ const method = toLogLevelName(callLevel);
198
+ const localName = toLogLevelName(localLevel);
199
+ [logLevels.none, logLevels.error, logLevels.warn, logLevels.info, logLevels.debug].forEach(globalLevel => {
200
+ const globalName = toLogLevelName(globalLevel) || 'none';
201
+ test(`${method}() should not log on local level: ${localName} (${localLevel}) while global level: ${globalName} (${globalLevel})`, () => {
202
+ const sl = createStandardLogForTest(globalLevel);
203
+ return assertNotLoggedAtCallLevelOverrideLocalLevel(sl, method, localLevel, callLevel);
204
+ });
205
+ });
206
+ });
207
+ shouldNotLog('error', logLevels.none);
208
+ shouldLog('error', logLevels.error);
209
+ shouldLog('error', logLevels.warn);
210
+ shouldLog('error', logLevels.info);
211
+ shouldLog('error', logLevels.debug);
212
+ shouldNotLogWithLocalLevelOverride('error', logLevels.none);
213
+ shouldLogWithLocalLevelOverride('error', logLevels.error);
214
+ shouldLogWithLocalLevelOverride('error', logLevels.warn);
215
+ shouldLogWithLocalLevelOverride('error', logLevels.info);
216
+ shouldLogWithLocalLevelOverride('error', logLevels.debug);
217
+ shouldNotLog('warn', logLevels.none);
218
+ shouldNotLog('warn', logLevels.error);
219
+ shouldLog('warn', logLevels.warn);
220
+ shouldLog('warn', logLevels.info);
221
+ shouldLog('warn', logLevels.debug);
222
+ shouldNotLogWithLocalLevelOverride('warn', logLevels.none);
223
+ shouldNotLogWithLocalLevelOverride('warn', logLevels.error);
224
+ shouldLogWithLocalLevelOverride('warn', logLevels.warn);
225
+ shouldLogWithLocalLevelOverride('warn', logLevels.info);
226
+ shouldLogWithLocalLevelOverride('warn', logLevels.debug);
227
+ shouldNotLog('info', logLevels.none);
228
+ shouldNotLog('info', logLevels.error);
229
+ shouldNotLog('info', logLevels.warn);
230
+ shouldLog('info', logLevels.info);
231
+ shouldLog('info', logLevels.debug);
232
+ shouldNotLogWithLocalLevelOverride('info', logLevels.none);
233
+ shouldNotLogWithLocalLevelOverride('info', logLevels.error);
234
+ shouldNotLogWithLocalLevelOverride('info', logLevels.warn);
235
+ shouldLogWithLocalLevelOverride('info', logLevels.info);
236
+ shouldLogWithLocalLevelOverride('info', logLevels.debug);
237
+ shouldNotLog('debug', logLevels.none);
238
+ shouldNotLog('debug', logLevels.error);
239
+ shouldNotLog('debug', logLevels.warn);
240
+ shouldNotLog('debug', logLevels.info);
241
+ shouldLog('debug', logLevels.debug);
242
+ shouldNotLogWithLocalLevelOverride('debug', logLevels.none);
243
+ shouldNotLogWithLocalLevelOverride('debug', logLevels.error);
244
+ shouldNotLogWithLocalLevelOverride('debug', logLevels.warn);
245
+ shouldNotLogWithLocalLevelOverride('debug', logLevels.info);
246
+ shouldLogWithLocalLevelOverride('debug', logLevels.debug);
247
+ shouldNotCallLogFunction(logLevels.error, logLevels.none);
248
+ shouldCallLogFunction(logLevels.error, logLevels.error);
249
+ shouldCallLogFunction(logLevels.error, logLevels.warn);
250
+ shouldCallLogFunction(logLevels.error, logLevels.info);
251
+ shouldCallLogFunction(logLevels.error, logLevels.debug);
252
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.none);
253
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.error);
254
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.warn);
255
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.info);
256
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.error, logLevels.debug);
257
+ shouldNotCallLogFunction(logLevels.warn, logLevels.none);
258
+ shouldNotCallLogFunction(logLevels.warn, logLevels.error);
259
+ shouldCallLogFunction(logLevels.warn, logLevels.warn);
260
+ shouldCallLogFunction(logLevels.warn, logLevels.info);
261
+ shouldCallLogFunction(logLevels.warn, logLevels.debug);
262
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.none);
263
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.error);
264
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.warn);
265
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.info);
266
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.warn, logLevels.debug);
267
+ shouldNotCallLogFunction(logLevels.info, logLevels.none);
268
+ shouldNotCallLogFunction(logLevels.info, logLevels.error);
269
+ shouldNotCallLogFunction(logLevels.info, logLevels.warn);
270
+ shouldCallLogFunction(logLevels.info, logLevels.info);
271
+ shouldCallLogFunction(logLevels.info, logLevels.debug);
272
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.none);
273
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.error);
274
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.warn);
275
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.info);
276
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.info, logLevels.debug);
277
+ shouldNotCallLogFunction(logLevels.debug, logLevels.none);
278
+ shouldNotCallLogFunction(logLevels.debug, logLevels.error);
279
+ shouldNotCallLogFunction(logLevels.debug, logLevels.warn);
280
+ shouldNotCallLogFunction(logLevels.debug, logLevels.info);
281
+ shouldCallLogFunction(logLevels.debug, logLevels.debug);
282
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.none);
283
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.error);
284
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.warn);
285
+ shouldNotCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.info);
286
+ shouldCallLogFunctionWithLocalLevelOverride(logLevels.debug, logLevels.debug);
287
+ });
288
+ it('writes entry directly', () => {
289
+ const sl = createStandardLogForTest();
290
+ const log = sl.getLogger(['write-entry']);
291
+ const entry = { id: 'write-entry', level: logLevels.info, args: ['abc'], timestamp: new Date() };
292
+ log.write(entry);
293
+ a.satisfies(sl.reporter.logs, [entry]);
294
+ });
295
+ test.each(['on', 'count', 'error', 'warn', 'info', 'debug'])('method %s is readonly', name => {
296
+ const sl = createStandardLog();
297
+ const log = sl.getLogger([`${name} is readonly`]);
298
+ a.throws(() => log[name] = true);
299
+ });
300
+ describe('on()', () => {
301
+ it('log using log argument', () => {
302
+ const sl = createStandardLogForTest();
303
+ const logger = sl.getLogger(['log on fn']);
304
+ logger.on('error', log => { log('value'); });
305
+ a.satisfies(sl.reporter.logs, [
306
+ { id: 'log on fn', level: logLevels.error, args: ['value'] }
307
+ ]);
308
+ });
309
+ it('can take log level name in first argument', () => {
310
+ const sl = createStandardLogForTest();
311
+ const log = sl.getLogger(['string-on']);
312
+ log.on('debug', () => { return; });
313
+ });
314
+ });
315
+ describe('count()', () => {
316
+ test('will increment the counter', async () => {
317
+ const sl = createStandardLogForTest();
318
+ const logger = sl.getLogger(['inc counter']);
319
+ logger.count();
320
+ logger.count();
321
+ a.satisfies(sl.reporter.logs, [
322
+ { id: 'inc counter', level: logLevels.debug, args: [1] },
323
+ { id: 'inc counter', level: logLevels.debug, args: [2] }
324
+ ]);
325
+ });
326
+ test('append args after the counter', async () => {
327
+ const sl = createStandardLogForTest(logLevels.debug);
328
+ const id = 'inc with args';
329
+ const logger = sl.getLogger([id]);
330
+ logger.count('msg1', 'msg2');
331
+ a.satisfies(sl.reporter.logs, [
332
+ { id, level: logLevels.debug, args: [1, 'msg1', 'msg2'] }
333
+ ]);
334
+ });
335
+ test('not log if log level is less than debug', async () => {
336
+ const sl = createStandardLogForTest(logLevels.debug - 1);
337
+ const id = 'inc with args';
338
+ const logger = sl.getLogger([id]);
339
+ logger.count('msg1', 'msg2');
340
+ expect(sl.reporter.logs.length).toBe(0);
341
+ });
342
+ });
343
+ test('logger with custom level', async () => {
344
+ const mem = createMemoryLogReporter();
345
+ const sl = createStandardLog({ customLevels: { 'cust_lvl': 100 }, reporters: [mem] });
346
+ const logger = sl.getLogger(['cust']);
347
+ logger.cust_lvl('a', 'b');
348
+ a.satisfies(mem.logs, [{ id: 'cust', level: 100, args: ['a', 'b'] }]);
349
+ });
350
+ describe('getLogger([,{ writeTo }])', () => {
351
+ function testWriteTo(loggerParams, handler) {
352
+ const memReporter = createMemoryLogReporter();
353
+ const specialReporter = createMemoryLogReporter({ id: 'special' });
354
+ const sl = createStandardLog({ reporters: [memReporter, specialReporter] });
355
+ const log = sl.getLogger(loggerParams);
356
+ handler(log, memReporter.logs, specialReporter.logs, sl);
357
+ }
358
+ it('can specify which reporter to use by name', () => {
359
+ testWriteTo(['writeTo-string', { writeTo: 'special' }], (log, memLogs, specialLogs) => {
360
+ log.error('error message');
361
+ expect(memLogs.length).toEqual(0);
362
+ expect(specialLogs.length).toEqual(1);
363
+ });
364
+ });
365
+ it('can specify which reporter to use by regex', () => {
366
+ testWriteTo(['writeTo-regex', { writeTo: /^spec/ }], (log, memLogs, specialLogs) => {
367
+ log.error('error message');
368
+ expect(memLogs.length).toEqual(0);
369
+ expect(specialLogs.length).toEqual(1);
370
+ });
371
+ });
372
+ it('can specify which reporter to use by RegExp', () => {
373
+ testWriteTo(['writeTo-RegExp', { writeTo: new RegExp('^spec') }], (log, memLogs, specialLogs) => {
374
+ log.error('error message');
375
+ expect(memLogs.length).toEqual(0);
376
+ expect(specialLogs.length).toEqual(1);
377
+ });
378
+ });
379
+ it('can specify which reporter to use by function', () => {
380
+ testWriteTo(['writeTo-fn', { writeTo: id => id === 'special' }], (log, memLogs, specialLogs) => {
381
+ log.error('error message');
382
+ expect(memLogs.length).toEqual(0);
383
+ expect(specialLogs.length).toEqual(1);
384
+ });
385
+ });
386
+ it('can specify custom reporter', () => {
387
+ const reporter = createMemoryLogReporter({ id: 'custom mem' });
388
+ testWriteTo(['writeTo-reporter', { writeTo: reporter }], (log, memLogs, specialLogs) => {
389
+ log.error('error message');
390
+ expect(memLogs.length).toEqual(0);
391
+ expect(specialLogs.length).toEqual(0);
392
+ expect(reporter.logs.length).toEqual(1);
393
+ });
394
+ });
395
+ test('the custom console reporter cannot pick up logs from other loggers', () => {
396
+ // if not, it would be a security issue as the new reporter
397
+ // can capture the logs from other logger and send it elsewhere
398
+ const reporter = createMemoryLogReporter({ id: 'custom mem' });
399
+ testWriteTo(['writeTo-reporter-no-override', { writeTo: reporter }], (_, memLogs, specialLogs, sl) => {
400
+ const log = sl.getLogger(['writeTo-reporter-no-override-2']);
401
+ log.error('error message');
402
+ expect(reporter.logs.length).toEqual(0);
403
+ });
404
+ });
405
+ });
406
+ });
407
+ describe('suppressLogs()', () => {
408
+ test('suppress log', () => {
409
+ const sl = createStandardLogForTest();
410
+ const log = sl.getLogger(['l']);
411
+ suppressLogs(() => {
412
+ log.alert('should not see me');
413
+ }, log);
414
+ expect(sl.reporter.getLogMessageWithLevel()).toBe('');
415
+ });
416
+ test('suppress multiple logs', () => {
417
+ const sl = createStandardLogForTest();
418
+ const log1 = sl.getLogger(['l1']);
419
+ const log2 = sl.getLogger(['l2']);
420
+ suppressLogs(() => {
421
+ log1.alert('should not see me');
422
+ log2.alert('should not see me too');
423
+ }, log1, log2);
424
+ expect(sl.reporter.getLogMessageWithLevel()).toBe('');
425
+ });
426
+ test('return block result', () => {
427
+ const sl = createStandardLogForTest();
428
+ const log1 = sl.getLogger(['l']);
429
+ const log2 = sl.getLogger(['l2']);
430
+ const a = suppressLogs(() => 1, log1, log2);
431
+ expect(a).toBe(1);
432
+ });
433
+ });
434
+ //# sourceMappingURL=standardLog.spec.js.map