standard-log 8.0.1 → 9.1.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 (624) 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 +74 -0
  5. package/cjs/console.js.map +1 -0
  6. package/cjs/console.spec.d.ts +2 -0
  7. package/cjs/console.spec.d.ts.map +1 -0
  8. package/cjs/{console/createConsoleLogReporter.spec.js → console.spec.js} +50 -68
  9. package/cjs/console.spec.js.map +1 -0
  10. package/cjs/errors.d.ts +0 -10
  11. package/cjs/errors.d.ts.map +1 -1
  12. package/cjs/errors.js +1 -43
  13. package/cjs/errors.js.map +1 -1
  14. package/cjs/formatter.d.ts +6 -0
  15. package/cjs/formatter.d.ts.map +1 -0
  16. package/cjs/formatter.js +46 -0
  17. package/cjs/formatter.js.map +1 -0
  18. package/cjs/formatter.spec.d.ts +2 -0
  19. package/cjs/formatter.spec.d.ts.map +1 -0
  20. package/cjs/formatter.spec.js +32 -0
  21. package/cjs/formatter.spec.js.map +1 -0
  22. package/cjs/global.d.ts +13 -0
  23. package/cjs/global.d.ts.map +1 -0
  24. package/cjs/global.js +33 -0
  25. package/cjs/global.js.map +1 -0
  26. package/cjs/global.spec.d.ts +2 -0
  27. package/cjs/global.spec.d.ts.map +1 -0
  28. package/cjs/global.spec.js +32 -0
  29. package/cjs/global.spec.js.map +1 -0
  30. package/cjs/index.d.ts +6 -14
  31. package/cjs/index.d.ts.map +1 -1
  32. package/cjs/index.js +11 -14
  33. package/cjs/index.js.map +1 -1
  34. package/cjs/logLevels.d.ts +60 -0
  35. package/cjs/logLevels.d.ts.map +1 -0
  36. package/cjs/logLevels.js +87 -0
  37. package/cjs/logLevels.js.map +1 -0
  38. package/cjs/logStore.d.ts +20 -0
  39. package/cjs/logStore.d.ts.map +1 -0
  40. package/cjs/logStore.js +44 -0
  41. package/cjs/logStore.js.map +1 -0
  42. package/cjs/logStore.spec.d.ts +2 -0
  43. package/cjs/logStore.spec.d.ts.map +1 -0
  44. package/cjs/logStore.spec.js +93 -0
  45. package/cjs/logStore.spec.js.map +1 -0
  46. package/cjs/logger.d.ts +5 -0
  47. package/cjs/logger.d.ts.map +1 -0
  48. package/cjs/logger.js +99 -0
  49. package/cjs/logger.js.map +1 -0
  50. package/{esm/memory/MemoryLogReporter.d.ts → cjs/memory.d.ts} +2 -2
  51. package/cjs/memory.d.ts.map +1 -0
  52. package/cjs/memory.js +39 -0
  53. package/cjs/memory.js.map +1 -0
  54. package/cjs/memory.spec.d.ts +2 -0
  55. package/cjs/memory.spec.d.ts.map +1 -0
  56. package/cjs/memory.spec.js +115 -0
  57. package/cjs/memory.spec.js.map +1 -0
  58. package/cjs/package.json +1 -3
  59. package/cjs/platform.browser.d.ts +6 -0
  60. package/cjs/platform.browser.d.ts.map +1 -0
  61. package/cjs/platform.browser.js +7 -0
  62. package/cjs/platform.browser.js.map +1 -0
  63. package/cjs/platform.d.ts +6 -0
  64. package/cjs/platform.d.ts.map +1 -0
  65. package/cjs/platform.js +9 -0
  66. package/cjs/platform.js.map +1 -0
  67. package/cjs/standardLog.d.ts +28 -0
  68. package/cjs/standardLog.d.ts.map +1 -0
  69. package/cjs/standardLog.js +65 -0
  70. package/cjs/standardLog.js.map +1 -0
  71. package/cjs/standardLog.spec.d.ts +2 -0
  72. package/cjs/standardLog.spec.d.ts.map +1 -0
  73. package/cjs/standardLog.spec.js +548 -0
  74. package/cjs/standardLog.spec.js.map +1 -0
  75. package/cjs/testUtil.d.ts +7 -5
  76. package/cjs/testUtil.d.ts.map +1 -1
  77. package/cjs/testUtil.js +11 -14
  78. package/cjs/testUtil.js.map +1 -1
  79. package/cjs/types.d.ts +33 -24
  80. package/cjs/types.d.ts.map +1 -1
  81. package/cjs/types.js.map +1 -1
  82. package/dist/standard-log.es5.js +355 -1071
  83. package/dist/standard-log.es5.js.gz +0 -0
  84. package/dist/standard-log.es5.js.map +1 -1
  85. package/dist/standard-log.es5.js.map.gz +0 -0
  86. package/dist/standard-log.esm.js +353 -1135
  87. package/dist/standard-log.esm.js.gz +0 -0
  88. package/dist/standard-log.esm.js.map +1 -1
  89. package/dist/standard-log.esm.js.map.gz +0 -0
  90. package/{cjs/console/createConsoleLogReporter.d.ts → esm/console.d.ts} +5 -5
  91. package/esm/console.d.ts.map +1 -0
  92. package/esm/console.js +62 -0
  93. package/esm/console.js.map +1 -0
  94. package/esm/console.spec.d.ts +2 -0
  95. package/esm/console.spec.d.ts.map +1 -0
  96. package/esm/{console/createConsoleLogReporter.spec.js → console.spec.js} +50 -65
  97. package/esm/console.spec.js.map +1 -0
  98. package/esm/errors.d.ts +0 -10
  99. package/esm/errors.d.ts.map +1 -1
  100. package/esm/errors.js +0 -34
  101. package/esm/errors.js.map +1 -1
  102. package/esm/formatter.d.ts +6 -0
  103. package/esm/formatter.d.ts.map +1 -0
  104. package/esm/{formatter/createTimestampFormatter.js → formatter.js} +10 -2
  105. package/esm/formatter.js.map +1 -0
  106. package/esm/formatter.spec.d.ts +2 -0
  107. package/esm/formatter.spec.d.ts.map +1 -0
  108. package/esm/formatter.spec.js +30 -0
  109. package/esm/formatter.spec.js.map +1 -0
  110. package/esm/global.d.ts +13 -0
  111. package/esm/global.d.ts.map +1 -0
  112. package/esm/global.js +28 -0
  113. package/esm/global.js.map +1 -0
  114. package/esm/global.spec.d.ts +2 -0
  115. package/esm/global.spec.d.ts.map +1 -0
  116. package/esm/global.spec.js +30 -0
  117. package/esm/global.spec.js.map +1 -0
  118. package/esm/index.d.ts +6 -14
  119. package/esm/index.d.ts.map +1 -1
  120. package/esm/index.js +6 -14
  121. package/esm/index.js.map +1 -1
  122. package/esm/logLevels.d.ts +60 -0
  123. package/esm/logLevels.d.ts.map +1 -0
  124. package/esm/{logLevel.js → logLevels.js} +29 -3
  125. package/esm/logLevels.js.map +1 -0
  126. package/esm/logStore.d.ts +20 -0
  127. package/esm/logStore.d.ts.map +1 -0
  128. package/esm/logStore.js +37 -0
  129. package/esm/logStore.js.map +1 -0
  130. package/esm/logStore.spec.d.ts +2 -0
  131. package/esm/logStore.spec.d.ts.map +1 -0
  132. package/esm/logStore.spec.js +93 -0
  133. package/esm/logStore.spec.js.map +1 -0
  134. package/esm/logger.d.ts +5 -0
  135. package/esm/logger.d.ts.map +1 -0
  136. package/esm/logger.js +75 -0
  137. package/esm/logger.js.map +1 -0
  138. package/{cjs/memory/MemoryLogReporter.d.ts → esm/memory.d.ts} +2 -2
  139. package/esm/memory.d.ts.map +1 -0
  140. package/esm/memory.js +34 -0
  141. package/esm/memory.js.map +1 -0
  142. package/esm/memory.spec.d.ts +2 -0
  143. package/esm/memory.spec.d.ts.map +1 -0
  144. package/esm/memory.spec.js +110 -0
  145. package/esm/memory.spec.js.map +1 -0
  146. package/esm/platform.browser.d.ts +6 -0
  147. package/esm/platform.browser.d.ts.map +1 -0
  148. package/esm/platform.browser.js +3 -0
  149. package/esm/platform.browser.js.map +1 -0
  150. package/esm/platform.d.ts +6 -0
  151. package/esm/platform.d.ts.map +1 -0
  152. package/esm/platform.js +5 -0
  153. package/esm/platform.js.map +1 -0
  154. package/esm/standardLog.d.ts +28 -0
  155. package/esm/standardLog.d.ts.map +1 -0
  156. package/esm/standardLog.js +41 -0
  157. package/esm/standardLog.js.map +1 -0
  158. package/esm/standardLog.spec.d.ts +2 -0
  159. package/esm/standardLog.spec.d.ts.map +1 -0
  160. package/esm/standardLog.spec.js +446 -0
  161. package/esm/standardLog.spec.js.map +1 -0
  162. package/esm/testUtil.d.ts +7 -5
  163. package/esm/testUtil.d.ts.map +1 -1
  164. package/esm/testUtil.js +8 -12
  165. package/esm/testUtil.js.map +1 -1
  166. package/esm/types.d.ts +33 -24
  167. package/esm/types.d.ts.map +1 -1
  168. package/esm/types.js.map +1 -1
  169. package/package.json +10 -19
  170. package/ts/console.ts +70 -0
  171. package/ts/errors.ts +0 -12
  172. package/ts/{formatter/createTimestampFormatter.ts → formatter.ts} +12 -1
  173. package/ts/global.ts +34 -0
  174. package/ts/index.ts +9 -14
  175. package/ts/{logLevel.ts → logLevels.ts} +20 -3
  176. package/ts/logStore.ts +52 -0
  177. package/ts/logger.ts +85 -0
  178. package/ts/memory.ts +47 -0
  179. package/ts/platform.browser.ts +5 -0
  180. package/ts/platform.ts +8 -0
  181. package/ts/standardLog.ts +65 -0
  182. package/ts/types.ts +39 -30
  183. package/cjs/LogEntry.d.ts +0 -7
  184. package/cjs/LogEntry.d.ts.map +0 -1
  185. package/cjs/LogEntry.js +0 -3
  186. package/cjs/LogEntry.js.map +0 -1
  187. package/cjs/captureLogs.d.ts +0 -4
  188. package/cjs/captureLogs.d.ts.map +0 -1
  189. package/cjs/captureLogs.js +0 -33
  190. package/cjs/captureLogs.js.map +0 -1
  191. package/cjs/captureLogs.spec.d.ts +0 -2
  192. package/cjs/captureLogs.spec.d.ts.map +0 -1
  193. package/cjs/captureLogs.spec.js +0 -117
  194. package/cjs/captureLogs.spec.js.map +0 -1
  195. package/cjs/config.d.ts +0 -12
  196. package/cjs/config.d.ts.map +0 -1
  197. package/cjs/config.js +0 -59
  198. package/cjs/config.js.map +0 -1
  199. package/cjs/config.spec.d.ts +0 -2
  200. package/cjs/config.spec.d.ts.map +0 -1
  201. package/cjs/config.spec.js +0 -72
  202. package/cjs/config.spec.js.map +0 -1
  203. package/cjs/configForTest.d.ts +0 -5
  204. package/cjs/configForTest.d.ts.map +0 -1
  205. package/cjs/configForTest.js +0 -18
  206. package/cjs/configForTest.js.map +0 -1
  207. package/cjs/configForTest.spec.d.ts +0 -2
  208. package/cjs/configForTest.spec.d.ts.map +0 -1
  209. package/cjs/configForTest.spec.js +0 -17
  210. package/cjs/configForTest.spec.js.map +0 -1
  211. package/cjs/console/createConsoleLogReporter.d.ts.map +0 -1
  212. package/cjs/console/createConsoleLogReporter.js +0 -42
  213. package/cjs/console/createConsoleLogReporter.js.map +0 -1
  214. package/cjs/console/createConsoleLogReporter.spec.d.ts +0 -2
  215. package/cjs/console/createConsoleLogReporter.spec.d.ts.map +0 -1
  216. package/cjs/console/createConsoleLogReporter.spec.js.map +0 -1
  217. package/cjs/console/index.d.ts +0 -4
  218. package/cjs/console/index.d.ts.map +0 -1
  219. package/cjs/console/index.js +0 -20
  220. package/cjs/console/index.js.map +0 -1
  221. package/cjs/console/isConsoleDebugAvailable.d.ts +0 -2
  222. package/cjs/console/isConsoleDebugAvailable.d.ts.map +0 -1
  223. package/cjs/console/isConsoleDebugAvailable.js +0 -20
  224. package/cjs/console/isConsoleDebugAvailable.js.map +0 -1
  225. package/cjs/console/polyfilledConsole.d.ts +0 -7
  226. package/cjs/console/polyfilledConsole.d.ts.map +0 -1
  227. package/cjs/console/polyfilledConsole.js +0 -41
  228. package/cjs/console/polyfilledConsole.js.map +0 -1
  229. package/cjs/console/semverGt.d.ts +0 -2
  230. package/cjs/console/semverGt.d.ts.map +0 -1
  231. package/cjs/console/semverGt.js +0 -13
  232. package/cjs/console/semverGt.js.map +0 -1
  233. package/cjs/console/semverGt.spec.d.ts +0 -2
  234. package/cjs/console/semverGt.spec.d.ts.map +0 -1
  235. package/cjs/console/semverGt.spec.js +0 -22
  236. package/cjs/console/semverGt.spec.js.map +0 -1
  237. package/cjs/console/toConsoleMethod.d.ts +0 -2
  238. package/cjs/console/toConsoleMethod.d.ts.map +0 -1
  239. package/cjs/console/toConsoleMethod.js +0 -22
  240. package/cjs/console/toConsoleMethod.js.map +0 -1
  241. package/cjs/console/types.d.ts +0 -3
  242. package/cjs/console/types.d.ts.map +0 -1
  243. package/cjs/console/types.js +0 -3
  244. package/cjs/console/types.js.map +0 -1
  245. package/cjs/customLogLevel.d.ts +0 -11
  246. package/cjs/customLogLevel.d.ts.map +0 -1
  247. package/cjs/customLogLevel.js +0 -38
  248. package/cjs/customLogLevel.js.map +0 -1
  249. package/cjs/customLogLevel.spec.d.ts +0 -2
  250. package/cjs/customLogLevel.spec.d.ts.map +0 -1
  251. package/cjs/customLogLevel.spec.js +0 -37
  252. package/cjs/customLogLevel.spec.js.map +0 -1
  253. package/cjs/formatter/createTimestampFormatter.d.ts +0 -3
  254. package/cjs/formatter/createTimestampFormatter.d.ts.map +0 -1
  255. package/cjs/formatter/createTimestampFormatter.js +0 -26
  256. package/cjs/formatter/createTimestampFormatter.js.map +0 -1
  257. package/cjs/formatter/createTimestampFormatter.spec.d.ts +0 -2
  258. package/cjs/formatter/createTimestampFormatter.spec.d.ts.map +0 -1
  259. package/cjs/formatter/createTimestampFormatter.spec.js +0 -23
  260. package/cjs/formatter/createTimestampFormatter.spec.js.map +0 -1
  261. package/cjs/formatter/formatLogLevel.d.ts +0 -2
  262. package/cjs/formatter/formatLogLevel.d.ts.map +0 -1
  263. package/cjs/formatter/formatLogLevel.js +0 -10
  264. package/cjs/formatter/formatLogLevel.js.map +0 -1
  265. package/cjs/formatter/index.d.ts +0 -4
  266. package/cjs/formatter/index.d.ts.map +0 -1
  267. package/cjs/formatter/index.js +0 -20
  268. package/cjs/formatter/index.js.map +0 -1
  269. package/cjs/formatter/plainLogFormatter.d.ts +0 -3
  270. package/cjs/formatter/plainLogFormatter.d.ts.map +0 -1
  271. package/cjs/formatter/plainLogFormatter.js +0 -19
  272. package/cjs/formatter/plainLogFormatter.js.map +0 -1
  273. package/cjs/formatter/plainLogFormatter.spec.d.ts +0 -2
  274. package/cjs/formatter/plainLogFormatter.spec.d.ts.map +0 -1
  275. package/cjs/formatter/plainLogFormatter.spec.js +0 -9
  276. package/cjs/formatter/plainLogFormatter.spec.js.map +0 -1
  277. package/cjs/getDefaultReporter.browser.d.ts +0 -2
  278. package/cjs/getDefaultReporter.browser.d.ts.map +0 -1
  279. package/cjs/getDefaultReporter.browser.js +0 -15
  280. package/cjs/getDefaultReporter.browser.js.map +0 -1
  281. package/cjs/getDefaultReporter.d.ts +0 -2
  282. package/cjs/getDefaultReporter.d.ts.map +0 -1
  283. package/cjs/getDefaultReporter.js +0 -19
  284. package/cjs/getDefaultReporter.js.map +0 -1
  285. package/cjs/getLogModeFromEnvironment.browser.d.ts +0 -3
  286. package/cjs/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  287. package/cjs/getLogModeFromEnvironment.browser.js +0 -9
  288. package/cjs/getLogModeFromEnvironment.browser.js.map +0 -1
  289. package/cjs/getLogModeFromEnvironment.d.ts +0 -3
  290. package/cjs/getLogModeFromEnvironment.d.ts.map +0 -1
  291. package/cjs/getLogModeFromEnvironment.js +0 -17
  292. package/cjs/getLogModeFromEnvironment.js.map +0 -1
  293. package/cjs/getLogModeFromEnvironment.spec.d.ts +0 -2
  294. package/cjs/getLogModeFromEnvironment.spec.d.ts.map +0 -1
  295. package/cjs/getLogModeFromEnvironment.spec.js +0 -25
  296. package/cjs/getLogModeFromEnvironment.spec.js.map +0 -1
  297. package/cjs/getLogger.d.ts +0 -9
  298. package/cjs/getLogger.d.ts.map +0 -1
  299. package/cjs/getLogger.js +0 -103
  300. package/cjs/getLogger.js.map +0 -1
  301. package/cjs/getLogger.spec.d.ts +0 -2
  302. package/cjs/getLogger.spec.d.ts.map +0 -1
  303. package/cjs/getLogger.spec.js +0 -485
  304. package/cjs/getLogger.spec.js.map +0 -1
  305. package/cjs/getLoggers.d.ts +0 -7
  306. package/cjs/getLoggers.d.ts.map +0 -1
  307. package/cjs/getLoggers.js +0 -15
  308. package/cjs/getLoggers.js.map +0 -1
  309. package/cjs/logLevel.d.ts +0 -106
  310. package/cjs/logLevel.d.ts.map +0 -1
  311. package/cjs/logLevel.js +0 -59
  312. package/cjs/logLevel.js.map +0 -1
  313. package/cjs/logLevel.spec.d.ts +0 -2
  314. package/cjs/logLevel.spec.d.ts.map +0 -1
  315. package/cjs/logLevel.spec.js +0 -195
  316. package/cjs/logLevel.spec.js.map +0 -1
  317. package/cjs/logLevelFn.d.ts +0 -20
  318. package/cjs/logLevelFn.d.ts.map +0 -1
  319. package/cjs/logLevelFn.js +0 -76
  320. package/cjs/logLevelFn.js.map +0 -1
  321. package/cjs/logReporter.d.ts +0 -7
  322. package/cjs/logReporter.d.ts.map +0 -1
  323. package/cjs/logReporter.js +0 -29
  324. package/cjs/logReporter.js.map +0 -1
  325. package/cjs/logReporter.spec.d.ts +0 -2
  326. package/cjs/logReporter.spec.d.ts.map +0 -1
  327. package/cjs/logReporter.spec.js +0 -98
  328. package/cjs/logReporter.spec.js.map +0 -1
  329. package/cjs/logReporterInternal.d.ts +0 -3
  330. package/cjs/logReporterInternal.d.ts.map +0 -1
  331. package/cjs/logReporterInternal.js +0 -23
  332. package/cjs/logReporterInternal.js.map +0 -1
  333. package/cjs/memory/MemoryLogReporter.d.ts.map +0 -1
  334. package/cjs/memory/MemoryLogReporter.js +0 -56
  335. package/cjs/memory/MemoryLogReporter.js.map +0 -1
  336. package/cjs/memory/MemoryLogReporter.spec.d.ts +0 -2
  337. package/cjs/memory/MemoryLogReporter.spec.d.ts.map +0 -1
  338. package/cjs/memory/MemoryLogReporter.spec.js +0 -124
  339. package/cjs/memory/MemoryLogReporter.spec.js.map +0 -1
  340. package/cjs/memory/index.d.ts +0 -3
  341. package/cjs/memory/index.d.ts.map +0 -1
  342. package/cjs/memory/index.js +0 -19
  343. package/cjs/memory/index.js.map +0 -1
  344. package/cjs/memory/logEntriesToString.d.ts +0 -3
  345. package/cjs/memory/logEntriesToString.d.ts.map +0 -1
  346. package/cjs/memory/logEntriesToString.js +0 -10
  347. package/cjs/memory/logEntriesToString.js.map +0 -1
  348. package/cjs/memory/logEntriesToString.spec.d.ts +0 -2
  349. package/cjs/memory/logEntriesToString.spec.d.ts.map +0 -1
  350. package/cjs/memory/logEntriesToString.spec.js +0 -36
  351. package/cjs/memory/logEntriesToString.spec.js.map +0 -1
  352. package/cjs/memory/toInspectStringForObject.d.ts +0 -3
  353. package/cjs/memory/toInspectStringForObject.d.ts.map +0 -1
  354. package/cjs/memory/toInspectStringForObject.js +0 -17
  355. package/cjs/memory/toInspectStringForObject.js.map +0 -1
  356. package/cjs/shouldLog.d.ts +0 -8
  357. package/cjs/shouldLog.d.ts.map +0 -1
  358. package/cjs/shouldLog.js +0 -14
  359. package/cjs/shouldLog.js.map +0 -1
  360. package/cjs/store.d.ts +0 -3
  361. package/cjs/store.d.ts.map +0 -1
  362. package/cjs/store.js +0 -27
  363. package/cjs/store.js.map +0 -1
  364. package/cjs/suppressLogs.d.ts +0 -6
  365. package/cjs/suppressLogs.d.ts.map +0 -1
  366. package/cjs/suppressLogs.js +0 -17
  367. package/cjs/suppressLogs.js.map +0 -1
  368. package/cjs/suppressLogs.spec.d.ts +0 -2
  369. package/cjs/suppressLogs.spec.d.ts.map +0 -1
  370. package/cjs/suppressLogs.spec.js +0 -31
  371. package/cjs/suppressLogs.spec.js.map +0 -1
  372. package/cjs/typesInternal.d.ts +0 -20
  373. package/cjs/typesInternal.d.ts.map +0 -1
  374. package/cjs/typesInternal.js +0 -3
  375. package/cjs/typesInternal.js.map +0 -1
  376. package/cjs/utils.d.ts +0 -6
  377. package/cjs/utils.d.ts.map +0 -1
  378. package/cjs/utils.js +0 -15
  379. package/cjs/utils.js.map +0 -1
  380. package/cjs/writeToReporters.d.ts +0 -6
  381. package/cjs/writeToReporters.d.ts.map +0 -1
  382. package/cjs/writeToReporters.js +0 -22
  383. package/cjs/writeToReporters.js.map +0 -1
  384. package/cjs/writeToReporters.spec.d.ts +0 -2
  385. package/cjs/writeToReporters.spec.d.ts.map +0 -1
  386. package/cjs/writeToReporters.spec.js +0 -59
  387. package/cjs/writeToReporters.spec.js.map +0 -1
  388. package/esm/LogEntry.d.ts +0 -7
  389. package/esm/LogEntry.d.ts.map +0 -1
  390. package/esm/LogEntry.js +0 -2
  391. package/esm/LogEntry.js.map +0 -1
  392. package/esm/captureLogs.d.ts +0 -4
  393. package/esm/captureLogs.d.ts.map +0 -1
  394. package/esm/captureLogs.js +0 -29
  395. package/esm/captureLogs.js.map +0 -1
  396. package/esm/captureLogs.spec.d.ts +0 -2
  397. package/esm/captureLogs.spec.d.ts.map +0 -1
  398. package/esm/captureLogs.spec.js +0 -45
  399. package/esm/captureLogs.spec.js.map +0 -1
  400. package/esm/config.d.ts +0 -12
  401. package/esm/config.d.ts.map +0 -1
  402. package/esm/config.js +0 -44
  403. package/esm/config.js.map +0 -1
  404. package/esm/config.spec.d.ts +0 -2
  405. package/esm/config.spec.d.ts.map +0 -1
  406. package/esm/config.spec.js +0 -67
  407. package/esm/config.spec.js.map +0 -1
  408. package/esm/configForTest.d.ts +0 -5
  409. package/esm/configForTest.d.ts.map +0 -1
  410. package/esm/configForTest.js +0 -14
  411. package/esm/configForTest.js.map +0 -1
  412. package/esm/configForTest.spec.d.ts +0 -2
  413. package/esm/configForTest.spec.d.ts.map +0 -1
  414. package/esm/configForTest.spec.js +0 -15
  415. package/esm/configForTest.spec.js.map +0 -1
  416. package/esm/console/createConsoleLogReporter.d.ts.map +0 -1
  417. package/esm/console/createConsoleLogReporter.js +0 -37
  418. package/esm/console/createConsoleLogReporter.js.map +0 -1
  419. package/esm/console/createConsoleLogReporter.spec.d.ts +0 -2
  420. package/esm/console/createConsoleLogReporter.spec.d.ts.map +0 -1
  421. package/esm/console/createConsoleLogReporter.spec.js.map +0 -1
  422. package/esm/console/index.d.ts +0 -4
  423. package/esm/console/index.d.ts.map +0 -1
  424. package/esm/console/index.js +0 -4
  425. package/esm/console/index.js.map +0 -1
  426. package/esm/console/isConsoleDebugAvailable.d.ts +0 -2
  427. package/esm/console/isConsoleDebugAvailable.d.ts.map +0 -1
  428. package/esm/console/isConsoleDebugAvailable.js +0 -13
  429. package/esm/console/isConsoleDebugAvailable.js.map +0 -1
  430. package/esm/console/polyfilledConsole.d.ts +0 -7
  431. package/esm/console/polyfilledConsole.d.ts.map +0 -1
  432. package/esm/console/polyfilledConsole.js +0 -32
  433. package/esm/console/polyfilledConsole.js.map +0 -1
  434. package/esm/console/semverGt.d.ts +0 -2
  435. package/esm/console/semverGt.d.ts.map +0 -1
  436. package/esm/console/semverGt.js +0 -9
  437. package/esm/console/semverGt.js.map +0 -1
  438. package/esm/console/semverGt.spec.d.ts +0 -2
  439. package/esm/console/semverGt.spec.d.ts.map +0 -1
  440. package/esm/console/semverGt.spec.js +0 -20
  441. package/esm/console/semverGt.spec.js.map +0 -1
  442. package/esm/console/toConsoleMethod.d.ts +0 -2
  443. package/esm/console/toConsoleMethod.d.ts.map +0 -1
  444. package/esm/console/toConsoleMethod.js +0 -18
  445. package/esm/console/toConsoleMethod.js.map +0 -1
  446. package/esm/console/types.d.ts +0 -3
  447. package/esm/console/types.d.ts.map +0 -1
  448. package/esm/console/types.js +0 -2
  449. package/esm/console/types.js.map +0 -1
  450. package/esm/customLogLevel.d.ts +0 -11
  451. package/esm/customLogLevel.d.ts.map +0 -1
  452. package/esm/customLogLevel.js +0 -30
  453. package/esm/customLogLevel.js.map +0 -1
  454. package/esm/customLogLevel.spec.d.ts +0 -2
  455. package/esm/customLogLevel.spec.d.ts.map +0 -1
  456. package/esm/customLogLevel.spec.js +0 -32
  457. package/esm/customLogLevel.spec.js.map +0 -1
  458. package/esm/formatter/createTimestampFormatter.d.ts +0 -3
  459. package/esm/formatter/createTimestampFormatter.d.ts.map +0 -1
  460. package/esm/formatter/createTimestampFormatter.js.map +0 -1
  461. package/esm/formatter/createTimestampFormatter.spec.d.ts +0 -2
  462. package/esm/formatter/createTimestampFormatter.spec.d.ts.map +0 -1
  463. package/esm/formatter/createTimestampFormatter.spec.js +0 -21
  464. package/esm/formatter/createTimestampFormatter.spec.js.map +0 -1
  465. package/esm/formatter/formatLogLevel.d.ts +0 -2
  466. package/esm/formatter/formatLogLevel.d.ts.map +0 -1
  467. package/esm/formatter/formatLogLevel.js +0 -6
  468. package/esm/formatter/formatLogLevel.js.map +0 -1
  469. package/esm/formatter/index.d.ts +0 -4
  470. package/esm/formatter/index.d.ts.map +0 -1
  471. package/esm/formatter/index.js +0 -4
  472. package/esm/formatter/index.js.map +0 -1
  473. package/esm/formatter/plainLogFormatter.d.ts +0 -3
  474. package/esm/formatter/plainLogFormatter.d.ts.map +0 -1
  475. package/esm/formatter/plainLogFormatter.js +0 -5
  476. package/esm/formatter/plainLogFormatter.js.map +0 -1
  477. package/esm/formatter/plainLogFormatter.spec.d.ts +0 -2
  478. package/esm/formatter/plainLogFormatter.spec.d.ts.map +0 -1
  479. package/esm/formatter/plainLogFormatter.spec.js +0 -7
  480. package/esm/formatter/plainLogFormatter.spec.js.map +0 -1
  481. package/esm/getDefaultReporter.browser.d.ts +0 -2
  482. package/esm/getDefaultReporter.browser.d.ts.map +0 -1
  483. package/esm/getDefaultReporter.browser.js +0 -11
  484. package/esm/getDefaultReporter.browser.js.map +0 -1
  485. package/esm/getDefaultReporter.d.ts +0 -2
  486. package/esm/getDefaultReporter.d.ts.map +0 -1
  487. package/esm/getDefaultReporter.js +0 -15
  488. package/esm/getDefaultReporter.js.map +0 -1
  489. package/esm/getLogModeFromEnvironment.browser.d.ts +0 -3
  490. package/esm/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  491. package/esm/getLogModeFromEnvironment.browser.js +0 -5
  492. package/esm/getLogModeFromEnvironment.browser.js.map +0 -1
  493. package/esm/getLogModeFromEnvironment.d.ts +0 -3
  494. package/esm/getLogModeFromEnvironment.d.ts.map +0 -1
  495. package/esm/getLogModeFromEnvironment.js +0 -13
  496. package/esm/getLogModeFromEnvironment.js.map +0 -1
  497. package/esm/getLogModeFromEnvironment.spec.d.ts +0 -2
  498. package/esm/getLogModeFromEnvironment.spec.d.ts.map +0 -1
  499. package/esm/getLogModeFromEnvironment.spec.js +0 -20
  500. package/esm/getLogModeFromEnvironment.spec.js.map +0 -1
  501. package/esm/getLogger.d.ts +0 -9
  502. package/esm/getLogger.d.ts.map +0 -1
  503. package/esm/getLogger.js +0 -78
  504. package/esm/getLogger.js.map +0 -1
  505. package/esm/getLogger.spec.d.ts +0 -2
  506. package/esm/getLogger.spec.d.ts.map +0 -1
  507. package/esm/getLogger.spec.js +0 -385
  508. package/esm/getLogger.spec.js.map +0 -1
  509. package/esm/getLoggers.d.ts +0 -7
  510. package/esm/getLoggers.d.ts.map +0 -1
  511. package/esm/getLoggers.js +0 -11
  512. package/esm/getLoggers.js.map +0 -1
  513. package/esm/logLevel.d.ts +0 -106
  514. package/esm/logLevel.d.ts.map +0 -1
  515. package/esm/logLevel.js.map +0 -1
  516. package/esm/logLevel.spec.d.ts +0 -2
  517. package/esm/logLevel.spec.d.ts.map +0 -1
  518. package/esm/logLevel.spec.js +0 -148
  519. package/esm/logLevel.spec.js.map +0 -1
  520. package/esm/logLevelFn.d.ts +0 -20
  521. package/esm/logLevelFn.d.ts.map +0 -1
  522. package/esm/logLevelFn.js +0 -67
  523. package/esm/logLevelFn.js.map +0 -1
  524. package/esm/logReporter.d.ts +0 -7
  525. package/esm/logReporter.d.ts.map +0 -1
  526. package/esm/logReporter.js +0 -21
  527. package/esm/logReporter.js.map +0 -1
  528. package/esm/logReporter.spec.d.ts +0 -2
  529. package/esm/logReporter.spec.d.ts.map +0 -1
  530. package/esm/logReporter.spec.js +0 -93
  531. package/esm/logReporter.spec.js.map +0 -1
  532. package/esm/logReporterInternal.d.ts +0 -3
  533. package/esm/logReporterInternal.d.ts.map +0 -1
  534. package/esm/logReporterInternal.js +0 -19
  535. package/esm/logReporterInternal.js.map +0 -1
  536. package/esm/memory/MemoryLogReporter.d.ts.map +0 -1
  537. package/esm/memory/MemoryLogReporter.js +0 -51
  538. package/esm/memory/MemoryLogReporter.js.map +0 -1
  539. package/esm/memory/MemoryLogReporter.spec.d.ts +0 -2
  540. package/esm/memory/MemoryLogReporter.spec.d.ts.map +0 -1
  541. package/esm/memory/MemoryLogReporter.spec.js +0 -111
  542. package/esm/memory/MemoryLogReporter.spec.js.map +0 -1
  543. package/esm/memory/index.d.ts +0 -3
  544. package/esm/memory/index.d.ts.map +0 -1
  545. package/esm/memory/index.js +0 -3
  546. package/esm/memory/index.js.map +0 -1
  547. package/esm/memory/logEntriesToString.d.ts +0 -3
  548. package/esm/memory/logEntriesToString.d.ts.map +0 -1
  549. package/esm/memory/logEntriesToString.js +0 -6
  550. package/esm/memory/logEntriesToString.js.map +0 -1
  551. package/esm/memory/logEntriesToString.spec.d.ts +0 -2
  552. package/esm/memory/logEntriesToString.spec.d.ts.map +0 -1
  553. package/esm/memory/logEntriesToString.spec.js +0 -42
  554. package/esm/memory/logEntriesToString.spec.js.map +0 -1
  555. package/esm/memory/toInspectStringForObject.d.ts +0 -3
  556. package/esm/memory/toInspectStringForObject.d.ts.map +0 -1
  557. package/esm/memory/toInspectStringForObject.js +0 -11
  558. package/esm/memory/toInspectStringForObject.js.map +0 -1
  559. package/esm/shouldLog.d.ts +0 -8
  560. package/esm/shouldLog.d.ts.map +0 -1
  561. package/esm/shouldLog.js +0 -10
  562. package/esm/shouldLog.js.map +0 -1
  563. package/esm/store.d.ts +0 -3
  564. package/esm/store.d.ts.map +0 -1
  565. package/esm/store.js +0 -24
  566. package/esm/store.js.map +0 -1
  567. package/esm/suppressLogs.d.ts +0 -6
  568. package/esm/suppressLogs.d.ts.map +0 -1
  569. package/esm/suppressLogs.js +0 -9
  570. package/esm/suppressLogs.js.map +0 -1
  571. package/esm/suppressLogs.spec.d.ts +0 -2
  572. package/esm/suppressLogs.spec.d.ts.map +0 -1
  573. package/esm/suppressLogs.spec.js +0 -29
  574. package/esm/suppressLogs.spec.js.map +0 -1
  575. package/esm/typesInternal.d.ts +0 -20
  576. package/esm/typesInternal.d.ts.map +0 -1
  577. package/esm/typesInternal.js +0 -2
  578. package/esm/typesInternal.js.map +0 -1
  579. package/esm/utils.d.ts +0 -6
  580. package/esm/utils.d.ts.map +0 -1
  581. package/esm/utils.js +0 -11
  582. package/esm/utils.js.map +0 -1
  583. package/esm/writeToReporters.d.ts +0 -6
  584. package/esm/writeToReporters.d.ts.map +0 -1
  585. package/esm/writeToReporters.js +0 -18
  586. package/esm/writeToReporters.js.map +0 -1
  587. package/esm/writeToReporters.spec.d.ts +0 -2
  588. package/esm/writeToReporters.spec.d.ts.map +0 -1
  589. package/esm/writeToReporters.spec.js +0 -9
  590. package/esm/writeToReporters.spec.js.map +0 -1
  591. package/ts/LogEntry.ts +0 -7
  592. package/ts/captureLogs.ts +0 -35
  593. package/ts/config.ts +0 -57
  594. package/ts/configForTest.ts +0 -16
  595. package/ts/console/createConsoleLogReporter.ts +0 -48
  596. package/ts/console/index.ts +0 -3
  597. package/ts/console/isConsoleDebugAvailable.ts +0 -11
  598. package/ts/console/polyfilledConsole.ts +0 -34
  599. package/ts/console/semverGt.ts +0 -9
  600. package/ts/console/toConsoleMethod.ts +0 -18
  601. package/ts/console/types.ts +0 -3
  602. package/ts/customLogLevel.ts +0 -35
  603. package/ts/formatter/formatLogLevel.ts +0 -6
  604. package/ts/formatter/index.ts +0 -3
  605. package/ts/formatter/plainLogFormatter.ts +0 -6
  606. package/ts/getDefaultReporter.browser.ts +0 -13
  607. package/ts/getDefaultReporter.ts +0 -15
  608. package/ts/getLogModeFromEnvironment.browser.ts +0 -6
  609. package/ts/getLogModeFromEnvironment.ts +0 -16
  610. package/ts/getLogger.ts +0 -92
  611. package/ts/getLoggers.ts +0 -12
  612. package/ts/logLevelFn.ts +0 -72
  613. package/ts/logReporter.ts +0 -26
  614. package/ts/logReporterInternal.ts +0 -18
  615. package/ts/memory/MemoryLogReporter.ts +0 -72
  616. package/ts/memory/index.ts +0 -2
  617. package/ts/memory/logEntriesToString.ts +0 -7
  618. package/ts/memory/toInspectStringForObject.ts +0 -13
  619. package/ts/shouldLog.ts +0 -11
  620. package/ts/store.ts +0 -25
  621. package/ts/suppressLogs.ts +0 -14
  622. package/ts/typesInternal.ts +0 -21
  623. package/ts/utils.ts +0 -11
  624. package/ts/writeToReporters.ts +0 -20
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ var type_plus_1 = require("type-plus");
13
+ var logLevels_js_1 = require("./logLevels.js");
14
+ var logStore_js_1 = require("./logStore.js");
15
+ var testUtil_js_1 = require("./testUtil.js");
16
+ describe('getName()', function () {
17
+ it.each(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], (0, testUtil_js_1.rangeEntries)(99, 100, 'emergency'), true), (0, testUtil_js_1.rangeEntries)(199, 200, 'alert'), true), (0, testUtil_js_1.rangeEntries)(299, 300, 'critical'), true), (0, testUtil_js_1.rangeEntries)(399, 400, 'error'), true), (0, testUtil_js_1.rangeEntries)(499, 500, 'warn'), true), (0, testUtil_js_1.rangeEntries)(599, 600, 'notice'), true), (0, testUtil_js_1.rangeEntries)(699, 700, 'info'), true), (0, testUtil_js_1.rangeEntries)(799, 800, 'debug'), true), (0, testUtil_js_1.rangeEntries)(899, 900, 'trace'), true), (0, testUtil_js_1.rangeEntries)(9999999, 10000000, 'planck'), true))('convert %i to %s', function (level, logLevel) {
18
+ var store = (0, logStore_js_1.logLevelStore)({ customLevels: {} });
19
+ expect(store.getName(level)).toBe(logLevel);
20
+ });
21
+ it('gets custom log level name', function () {
22
+ var store = (0, logStore_js_1.logLevelStore)({ customLevels: { 'cust-name': 144 } });
23
+ expect(store.getName(144)).toBe('cust-name');
24
+ });
25
+ });
26
+ describe('getLevel()', function () {
27
+ it('get default log levels', function () {
28
+ var store = (0, logStore_js_1.logLevelStore)({ customLevels: {} });
29
+ var 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(function (n) { return 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', function () {
46
+ var store = (0, logStore_js_1.logLevelStore)({ customLevels: {} });
47
+ var 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(function (n) { return store.getLevel(n); })).toEqual([
60
+ 100, 200, 300, 400, 500, 600, 700, 800, 900, Infinity
61
+ ]);
62
+ });
63
+ it('gets custom log level', function () {
64
+ var store = (0, logStore_js_1.logLevelStore)({ customLevels: { 'cust-get': 123 } });
65
+ expect(store.getLevel('cust-get')).toBe(123);
66
+ });
67
+ });
68
+ describe('getAllLevels()', function () {
69
+ it('gets all default log levels except none and all', function () {
70
+ var store = (0, logStore_js_1.logLevelStore)({ customLevels: {} });
71
+ var actual = store.getAllLevels();
72
+ (0, type_plus_1.forEachKey)(logLevels_js_1.logLevels, function (name) {
73
+ if (name === 'none' || name === 'all') {
74
+ expect(actual.find(function (x) { return x.name === name; })).toBeUndefined();
75
+ }
76
+ else {
77
+ expect(actual.find(function (x) { return x.name === name; })).toEqual({ name: name, level: logLevels_js_1.logLevels[name] });
78
+ }
79
+ });
80
+ });
81
+ it('include custom level (even if they have the same level value as one of the default level)', function () {
82
+ var store = (0, logStore_js_1.logLevelStore)({
83
+ customLevels: {
84
+ 'info_a': 301,
85
+ 'info_b': logLevels_js_1.logLevels.info
86
+ }
87
+ });
88
+ var actual = store.getAllLevels();
89
+ expect(actual.find(function (x) { return x.name === 'info_a'; })).toEqual({ name: 'info_a', level: 301 });
90
+ expect(actual.find(function (x) { return x.name === 'info_b'; })).toEqual({ name: 'info_b', level: logLevels_js_1.logLevels.info });
91
+ });
92
+ });
93
+ //# sourceMappingURL=logStore.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logStore.spec.js","sourceRoot":"","sources":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AS,CAAC,IAAI;aACzB;SACF,CAAC,CAAA;QACF,IAAM,MAAM,GAAG,KAAK,CAAC,YAAY,EAAE,CAAA;QACnC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAnB,CAAmB,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;QACrF,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAnB,CAAmB,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,wBAAS,CAAC,IAAI,EAAE,CAAC,CAAA;IAClG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { forEachKey } from 'type-plus'\nimport { logLevels } from './logLevels.js'\nimport { logLevelStore } 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,5 @@
1
+ import type { StackTraceMeta } from '@just-func/types';
2
+ import { LogStore } from './logStore.js';
3
+ import type { Logger, LoggerOptions, LogMethodNames } from './types.js';
4
+ export declare function createLogger<T extends string = LogMethodNames>([store, id, options]: [LogStore, string, LoggerOptions | undefined], meta?: StackTraceMeta): Logger;
5
+ //# 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;AAGtD,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,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,GAAG,SAAS,CAAC,EACnE,IAAI,CAAC,EAAE,cAAc,GACpB,MAAM,CAyDR"}
package/cjs/logger.js ADDED
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createLogger = void 0;
13
+ var errors_js_1 = require("./errors.js");
14
+ var logLevels_js_1 = require("./logLevels.js");
15
+ function createLogger(_a, meta) {
16
+ var _b;
17
+ var store = _a[0], id = _a[1], options = _a[2];
18
+ validateId(id, meta);
19
+ var writeTo = (_b = options === null || options === void 0 ? void 0 : options.writeTo) !== null && _b !== void 0 ? _b : (function () { return true; });
20
+ var _c = typeof writeTo === 'string'
21
+ ? [function (id) { return id === writeTo; }, store.reporters]
22
+ : writeTo instanceof RegExp
23
+ ? [function (id) { return writeTo.test(id); }, store.reporters]
24
+ : typeof writeTo === 'function'
25
+ ? [writeTo, store.reporters]
26
+ : [function () { return true; }, [writeTo]], filter = _c[0], reporters = _c[1];
27
+ function write(entry) {
28
+ writeToReporters(reporters, entry, filter);
29
+ }
30
+ var logger = {
31
+ level: options === null || options === void 0 ? void 0 : options.level,
32
+ write: write
33
+ };
34
+ Object.defineProperties(logger, {
35
+ id: { value: id, writable: false },
36
+ count: {
37
+ writable: false,
38
+ value: (function (counter) { return function () {
39
+ var args = [];
40
+ for (var _i = 0; _i < arguments.length; _i++) {
41
+ args[_i] = arguments[_i];
42
+ }
43
+ var level = logLevels_js_1.logLevels.debug;
44
+ if (shouldLog(store, level, logger.level))
45
+ write({
46
+ id: id,
47
+ level: level,
48
+ args: __spreadArray([++counter], args, true),
49
+ timestamp: new Date()
50
+ });
51
+ }; })(0)
52
+ },
53
+ on: {
54
+ writable: false,
55
+ value: function (level, logFn) {
56
+ var logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level) : level;
57
+ if (shouldLog(store, logLevel, logger.level)) {
58
+ var methodName = store.logLevelStore.getName(logLevel);
59
+ var bindedMethod = logger[methodName].bind(logger);
60
+ var result = logFn(bindedMethod);
61
+ if (result)
62
+ bindedMethod(result);
63
+ }
64
+ }
65
+ }
66
+ });
67
+ store.logLevelStore.getAllLevels().forEach(function addMethod(_a) {
68
+ var name = _a.name, level = _a.level;
69
+ Object.defineProperty(logger, name, {
70
+ writable: false,
71
+ value: function () {
72
+ var args = [];
73
+ for (var _i = 0; _i < arguments.length; _i++) {
74
+ args[_i] = arguments[_i];
75
+ }
76
+ if (shouldLog(store, level, logger.level))
77
+ write({ id: id, level: level, args: args, timestamp: new Date() });
78
+ }
79
+ });
80
+ });
81
+ return logger;
82
+ }
83
+ exports.createLogger = createLogger;
84
+ function validateId(id, meta) {
85
+ if (/[`~!#$%^&*()=+[\]{},|<>?]/.test(id))
86
+ throw new errors_js_1.InvalidId(id, meta);
87
+ }
88
+ function writeToReporters(reporters, logEntry, filter) {
89
+ reporters.filter(function (r) { return filter(r.id); }).forEach(function (r) { return r.write(logEntry); });
90
+ }
91
+ /**
92
+ * Determines should you log.
93
+ * @param loggerLevel Log level of the logger.
94
+ * It can be undefined which the global log level will be used.
95
+ */
96
+ function shouldLog(store, targetLevel, loggerLevel) {
97
+ return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel);
98
+ }
99
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../ts/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,yCAAuC;AACvC,+CAA0C;AAK1C,SAAgB,YAAY,CAC1B,EAAmE,EACnE,IAAqB;;QADpB,KAAK,QAAA,EAAE,EAAE,QAAA,EAAE,OAAO,QAAA;IAGnB,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IACpB,IAAM,OAAO,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,mCAAI,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAA;IAC1C,IAAA,KAAwE,OAAO,OAAO,KAAK,QAAQ;QACvG,CAAC,CAAC,CAAC,UAAA,EAAE,IAAI,OAAA,EAAE,KAAK,OAAO,EAAd,CAAc,EAAE,KAAK,CAAC,SAAS,CAAC;QACzC,CAAC,CAAC,OAAO,YAAY,MAAM;YACzB,CAAC,CAAC,CAAC,UAAA,EAAE,IAAI,OAAA,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAhB,CAAgB,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,cAAM,OAAA,IAAI,EAAJ,CAAI,EAAE,CAAC,OAAO,CAAC,CAAC,EANxB,MAAM,QAAA,EAAE,SAAS,QAMO,CAAA;IAE/B,SAAS,KAAK,CAAC,KAAe;QAC5B,gBAAgB,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,IAAM,MAAM,GAAG;QACb,KA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,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 { 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, options]: [LogStore, string, LoggerOptions | undefined],\n meta?: StackTraceMeta\n): Logger {\n validateId(id, meta)\n const writeTo = options?.writeTo ?? (() => true)\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: options?.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/cjs/memory.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMemoryLogReporter = exports.toMessageWithLevel = void 0;
4
+ var type_plus_1 = require("type-plus");
5
+ var platform_js_1 = require("./platform.js");
6
+ var formatter_js_1 = require("./formatter.js");
7
+ function toMessageWithLevel(logs) {
8
+ return logs.map(platform_js_1.toInspectLogEntry)
9
+ .map(function (log) { return "".concat((0, formatter_js_1.formatLogLevel)(log.level), " ").concat(log.args.join(' ')); })
10
+ .join('\n')
11
+ // if it has more than this log,
12
+ // we assume it is running under tests,
13
+ // and remove this log to simplify testing.
14
+ .replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, '');
15
+ }
16
+ exports.toMessageWithLevel = toMessageWithLevel;
17
+ function createMemoryLogReporter(options) {
18
+ var _a = (0, type_plus_1.required)({ id: 'memory', formatter: function (e) { return e; } }, options), id = _a.id, formatter = _a.formatter, filter = _a.filter;
19
+ var logs = [];
20
+ return Object.freeze({
21
+ id: id,
22
+ get formatter() { return formatter; },
23
+ get filter() { return filter; },
24
+ logs: logs,
25
+ write: function (entry) {
26
+ if (filter && !filter(entry))
27
+ return;
28
+ logs.push(formatter(entry));
29
+ },
30
+ getLogMessage: function () {
31
+ return logs.map(platform_js_1.toInspectLogEntry)
32
+ .map(function (log) { return log.args.join(' '); })
33
+ .join('\n');
34
+ },
35
+ getLogMessageWithLevel: function () { return toMessageWithLevel(logs); }
36
+ });
37
+ }
38
+ exports.createMemoryLogReporter = createMemoryLogReporter;
39
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sour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AAA,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAlB,CAAkB,CAAC;iBAC9B,IAAI,CAAC,IAAI,CAAC,CAAA;QACf,CAAC;QACD,sBAAsB,gBAAK,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC;KAC7D,CAAC,CAAA;AACJ,CAAC;AAnBD,0DAmBC","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,115 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var assertron_1 = __importDefault(require("assertron"));
18
+ var index_js_1 = require("./index.js");
19
+ var testUtil_js_1 = require("./testUtil.js");
20
+ describe('MemoryLogReporter', function () {
21
+ it('filter is readonly', function () {
22
+ var reporter = (0, index_js_1.createMemoryLogReporter)();
23
+ var err = assertron_1.default.throws(function () { reporter.filter = function () { return true; }; }, function (err) { return /only a getter/.test(err); });
24
+ (0, testUtil_js_1.assertSSF)(err, __filename);
25
+ });
26
+ describe('unit tests', function () {
27
+ test('log entries are saved in the `logs` property', function () {
28
+ var reporter = (0, index_js_1.createMemoryLogReporter)();
29
+ var entry = { id: 'log', level: 1, args: ['some messages'], timestamp: new Date() };
30
+ reporter.write(entry);
31
+ expect(reporter.logs).toEqual([entry]);
32
+ });
33
+ test('can override id', function () {
34
+ var reporter = (0, index_js_1.createMemoryLogReporter)({ id: 'custom-id-mem' });
35
+ expect(reporter.id).toBe('custom-id-mem');
36
+ });
37
+ test('can filter', function () {
38
+ var filter = function (entry) { return entry.id !== 'secret'; };
39
+ var reporter = (0, index_js_1.createMemoryLogReporter)({ filter: filter });
40
+ expect(reporter.filter).toBe(filter);
41
+ reporter.write({ id: 'ok', level: 1, args: ['some messages'], timestamp: new Date() });
42
+ reporter.write({ id: 'secret', level: 1, args: ['some messages'], timestamp: new Date() });
43
+ expect(reporter.logs.length).toBe(1);
44
+ });
45
+ test('formatter can be used to pre-process the log', function () {
46
+ var formatter = function (entry) { return (__assign(__assign({}, entry), { args: entry.args.map(function (arg) { return arg === 'secret' ? '<censored>' : arg; }) })); };
47
+ var reporter = (0, index_js_1.createMemoryLogReporter)({ formatter: formatter });
48
+ expect(reporter.formatter).toBe(formatter);
49
+ var entry = { id: 'log', level: 1, args: ['a', 'secret', 'b'], timestamp: new Date() };
50
+ reporter.write(entry);
51
+ expect(reporter.logs[0].args[1]).toBe('<censored>');
52
+ });
53
+ describe('getLogMessages()', function () {
54
+ test('empty logs returns empty string', function () {
55
+ var reporter = (0, index_js_1.createMemoryLogReporter)();
56
+ expect(reporter.getLogMessage()).toEqual('');
57
+ });
58
+ test('print args', function () {
59
+ var reporter = (0, index_js_1.createMemoryLogReporter)();
60
+ var entry = { id: 'log', level: 1, args: ['miku', 'is', 'singing'], timestamp: new Date() };
61
+ reporter.write(entry);
62
+ expect(reporter.getLogMessage()).toEqual('miku is singing');
63
+ });
64
+ test('print object arg', function () {
65
+ var reporter = (0, index_js_1.createMemoryLogReporter)();
66
+ var entry = { id: 'log', level: 1, args: [{ 'miku': 'sing' }], timestamp: new Date() };
67
+ reporter.write(entry);
68
+ expect(reporter.getLogMessage()).toEqual("{ miku: 'sing' }");
69
+ });
70
+ });
71
+ describe('getLogMessageWithLevel', function () {
72
+ test('print with level', function () {
73
+ var reporter = (0, index_js_1.createMemoryLogReporter)();
74
+ reporter.write({ id: 'log', level: index_js_1.logLevels.info, args: ['msg 1'], timestamp: new Date() });
75
+ reporter.write({ id: 'log', level: index_js_1.logLevels.warn, args: ['msg 2'], timestamp: new Date() });
76
+ expect(reporter.getLogMessageWithLevel()).toEqual("(INFO) msg 1\n(WARN) msg 2");
77
+ });
78
+ });
79
+ });
80
+ });
81
+ describe('logEntriesToString()', function () {
82
+ test('convert log entries to string', function () {
83
+ var timestamp = new Date(2019, 6);
84
+ var actual = (0, testUtil_js_1.logEntriesToString)([
85
+ { id: 'log', level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: timestamp },
86
+ { id: 'log', level: index_js_1.logLevels.critical, args: ['critical'], timestamp: timestamp },
87
+ { id: 'log', level: index_js_1.logLevels.alert, args: ['alert'], timestamp: timestamp },
88
+ { id: 'log', level: index_js_1.logLevels.error, args: ['error'], timestamp: timestamp },
89
+ { id: 'log', level: index_js_1.logLevels.warn, args: ['warn'], timestamp: timestamp },
90
+ { id: 'log', level: index_js_1.logLevels.notice, args: ['notice'], timestamp: timestamp },
91
+ { id: 'log', level: index_js_1.logLevels.info, args: ['info'], timestamp: timestamp },
92
+ { id: 'log', level: index_js_1.logLevels.debug, args: ['debug'], timestamp: timestamp },
93
+ { id: 'log', level: index_js_1.logLevels.trace, args: ['trace'], timestamp: timestamp }
94
+ ]);
95
+ var iso = timestamp.toISOString();
96
+ expect(actual).toEqual("".concat(iso, ",log,(EMERGENCY),emergency\n").concat(iso, ",log,(CRITICAL),critical\n").concat(iso, ",log,(ALERT),alert\n").concat(iso, ",log,(ERROR),error\n").concat(iso, ",log,(WARN),warn\n").concat(iso, ",log,(NOTICE),notice\n").concat(iso, ",log,(INFO),info\n").concat(iso, ",log,(DEBUG),debug\n").concat(iso, ",log,(TRACE),trace"));
97
+ });
98
+ test('print out object', function () {
99
+ var timestamp = new Date(2021, 4);
100
+ var actual = (0, testUtil_js_1.logEntriesToString)([
101
+ { id: 'log', level: index_js_1.logLevels.info, args: ['a', { a: 1 }], timestamp: timestamp }
102
+ ]);
103
+ var iso = timestamp.toISOString();
104
+ expect(actual).toEqual("".concat(iso, ",log,(INFO),a,{ a: 1 }"));
105
+ });
106
+ test('print out array', function () {
107
+ var timestamp = new Date(2021, 4);
108
+ var actual = (0, testUtil_js_1.logEntriesToString)([
109
+ { id: 'log', level: index_js_1.logLevels.info, args: ['a', [1, 2, 3]], timestamp: timestamp }
110
+ ]);
111
+ var iso = timestamp.toISOString();
112
+ expect(actual).toEqual("".concat(iso, ",log,(INFO),a,[ 1, 2, 3 ]"));
113
+ });
114
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iCACH,GAAG,+BACH,GAAG,mCACH,GAAG,+BACH,GAAG,iCACH,GAAG,uBAAoB,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,kBAAkB,EAAE;QACvB,IAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;QACnC,IAAM,MAAM,GAAG,IAAA,gCAAkB,EAAC;YAChC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,oBAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,WAAA,EAAE;SACvE,CAAC,CAAA;QAEF,IAAM,GAAG,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;QACnC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAG,GAAG,2BAAwB,CAAC,CAAA;IACxD,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,iBAAiB,EAAE;QACtB,IAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;QACnC,IAAM,MAAM,GAAG,IAAA,gCAAkB,EAAC;YAChC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,oBAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,WAAA,EAAE;SACxE,CAAC,CAAA;QAEF,IAAM,GAAG,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;QACnC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAG,GAAG,8BAA2B,CAAC,CAAA;IAC3D,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","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"]}
package/cjs/package.json CHANGED
@@ -1,3 +1 @@
1
- {
2
- "type": "commonjs"
3
- }
1
+ {"type":"commonjs"}
@@ -0,0 +1,6 @@
1
+ import type { ConsoleLike, LogEntry } from './types.js';
2
+ export declare const toInspectLogEntry: (e: LogEntry) => LogEntry;
3
+ export declare const polyfill: {
4
+ console?: ConsoleLike;
5
+ };
6
+ //# 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;AAEnD,eAAO,MAAM,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAA;CAAO,CAAA"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.polyfill = exports.toInspectLogEntry = void 0;
4
+ var toInspectLogEntry = function (e) { return e; };
5
+ exports.toInspectLogEntry = toInspectLogEntry;
6
+ exports.polyfill = {};
7
+ //# sourceMappingURL=platform.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.browser.js","sourceRoot":"","sources":["../ts/platform.browser.ts"],"names":[],"mappings":";;;AAEO,IAAM,iBAAiB,GAAG,UAAC,CAAW,IAAK,OAAA,CAAC,EAAD,CAAC,CAAA;AAAtC,QAAA,iBAAiB,qBAAqB;AAEtC,QAAA,QAAQ,GAA8B,EAAE,CAAA","sourcesContent":["import type { ConsoleLike, LogEntry } from './types.js'\n\nexport const toInspectLogEntry = (e: LogEntry) => e\n\nexport const polyfill: { console?: ConsoleLike } = {}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { ConsoleLike, LogEntry } from './types.js';
2
+ export declare const toInspectLogEntry: (e: LogEntry) => LogEntry;
3
+ export declare const polyfill: {
4
+ console?: ConsoleLike;
5
+ };
6
+ //# 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,eAAO,MAAM,iBAAiB,MAAO,QAAQ,aAEzC,CAAA;AAEJ,eAAO,MAAM,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAA;CAAO,CAAA"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.polyfill = exports.toInspectLogEntry = void 0;
4
+ var util_1 = require("util");
5
+ var toInspectLogEntry = function (e) { return (e.args = e.args.map(function (value) { return typeof value === 'object' && value !== null ? (0, util_1.inspect)(value) : value; }),
6
+ e); };
7
+ exports.toInspectLogEntry = toInspectLogEntry;
8
+ exports.polyfill = {};
9
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":";;;AAAA,6BAA8B;AAGvB,IAAM,iBAAiB,GAAG,UAAC,CAAW,IAAK,OAAA,CAChD,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,UAAA,KAAK,IAAI,OAAA,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAApE,CAAoE,CAAC;IAClG,CAAC,CAAC,EAF8C,CAE9C,CAAA;AAFS,QAAA,iBAAiB,qBAE1B;AAES,QAAA,QAAQ,GAA8B,EAAE,CAAA","sourcesContent":["import { inspect } from 'util'\nimport type { ConsoleLike, LogEntry } from './types.js'\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,28 @@
1
+ import { StackTraceMeta } from '@just-func/types';
2
+ import { LogStore } from './logStore.js';
3
+ import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js';
4
+ export interface StandardLogInstance<N extends string = LogMethodNames> {
5
+ logLevel: number;
6
+ toLogLevelName(level: number): string;
7
+ toLogLevel(name: N): number;
8
+ getLogger(params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N | LogMethodNames>;
9
+ }
10
+ export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
11
+ }
12
+ export declare function createStandardLog<N extends string = LogMethodNames>(options?: StandardLogOptions<N>): StandardLog<N>;
13
+ export declare function createStandardLogClosure<N extends string = LogMethodNames>(options?: StandardLogOptions<N>): {
14
+ store: LogStore;
15
+ standardLog: StandardLog<N>;
16
+ };
17
+ export declare function createStandardLogForTest(logLevel?: LogLevel): {
18
+ reporter: import("./memory.js").MemoryLogReporter;
19
+ logLevel: number;
20
+ toLogLevelName: (level: number) => string;
21
+ toLogLevel: (name: LogMethodNames) => number;
22
+ getLogger: (params: [id: string, options?: LoggerOptions | undefined], meta?: StackTraceMeta | undefined) => Logger<LogMethodNames>;
23
+ };
24
+ /**
25
+ * Suppress logging within the code block.
26
+ */
27
+ export declare function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R;
28
+ //# 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;AAIjD,OAAO,EAAkB,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExD,OAAO,KAAK,EAAE,MAA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) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.suppressLogs = exports.createStandardLogForTest = exports.createStandardLogClosure = exports.createStandardLog = void 0;
15
+ var type_plus_1 = require("type-plus");
16
+ var logger_js_1 = require("./logger.js");
17
+ var logLevels_js_1 = require("./logLevels.js");
18
+ var logStore_js_1 = require("./logStore.js");
19
+ var memory_js_1 = require("./memory.js");
20
+ function createStandardLog(options) {
21
+ return createStandardLogClosure(options).standardLog;
22
+ }
23
+ exports.createStandardLog = createStandardLog;
24
+ function createStandardLogClosure(options) {
25
+ var store = (0, logStore_js_1.createLogStore)((0, type_plus_1.required)({ logLevel: logLevels_js_1.logLevels.info }, options));
26
+ return {
27
+ store: store,
28
+ standardLog: {
29
+ get logLevel() { return store.logLevel; },
30
+ toLogLevelName: function (level) {
31
+ return store.logLevelStore.getName(level);
32
+ },
33
+ toLogLevel: function (name) {
34
+ return store.logLevelStore.getLevel(name);
35
+ },
36
+ getLogger: function (_a, meta) {
37
+ var id = _a[0], options = _a[1];
38
+ if (store.loggers[id])
39
+ return store.loggers[id];
40
+ return store.loggers[id] = (0, logger_js_1.createLogger)([store, id, options], __assign({ ssf: this.getLogger }, meta));
41
+ }
42
+ }
43
+ };
44
+ }
45
+ exports.createStandardLogClosure = createStandardLogClosure;
46
+ function createStandardLogForTest(logLevel) {
47
+ if (logLevel === void 0) { logLevel = logLevels_js_1.logLevels.debug; }
48
+ var reporter = (0, memory_js_1.createMemoryLogReporter)();
49
+ var standardLog = createStandardLog({ reporters: [reporter], logLevel: logLevel });
50
+ return __assign(__assign({}, standardLog), { reporter: reporter });
51
+ }
52
+ exports.createStandardLogForTest = createStandardLogForTest;
53
+ function suppressLogs(block) {
54
+ var logs = [];
55
+ for (var _i = 1; _i < arguments.length; _i++) {
56
+ logs[_i - 1] = arguments[_i];
57
+ }
58
+ var origLevels = logs.map(function (l) { return l.level; });
59
+ logs.forEach(function (l) { return l.level = logLevels_js_1.logLevels.none; });
60
+ var result = block();
61
+ logs.forEach(function (l, i) { return l.level = origLevels[i]; });
62
+ return result;
63
+ }
64
+ exports.suppressLogs = suppressLogs;
65
+ //# sourceMappingURL=standardLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,uCAAoC;AACpC,yCAA0C;AAC1C,+CAA0C;AAC1C,6CAAwD;AACxD,yCAAqD;AAarD,SAAgB,iBAAiB,CAC/B,OAA+B;IAE/B,OAAO,wBAAwB,CAAC,OAAO,CAAC,CAAC,WAAW,CAAA;AACtD,CAAC;AAJD,8CAIC;AAED,SAAgB,wBAAwB,CACtC,OAA+B;IAE/B,IAAM,KAAK,GAAG,IAAA,4BAAc,EAAC,IAAA,oBAAQ,EAAC,EAAE,QAAQ,EAAE,wBAAS,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;IAE7E,OAAO;QACL,KAAK,OAAA;QACL,WAAW,EAAE;YACX,IAAI,QAAQ,KAAK,OAAO,KAAK,CAAC,QAAQ,CAAA,CAAC,CAAC;YAExC,cAAc,EAAd,UAAe,KAAa;gBAC1B,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YAC3C,CAAC;YACD,UAAU,EAAV,UAAW,IAAY;gBACrB,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;YAC3C,CAAC;YACD,SAAS,EAAT,UAAU,EAAoD,EAAE,IAAqB;oBAA1E,EAAE,QAAA,EAAE,OAAO,QAAA;gBACpB,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBAAE,OAAO,KAAK,CAA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\nimport { logLevels } from './logLevels.js'\nimport { createLogStore, LogStore } from './logStore.js'\nimport { createMemoryLogReporter } from './memory.js'\nimport type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js'\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n 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 interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {\n}\n\nexport function createStandardLog<N extends string = LogMethodNames>(\n options?: StandardLogOptions<N>\n): StandardLog<N> {\n return createStandardLogClosure(options).standardLog\n}\n\nexport function createStandardLogClosure<N extends string = LogMethodNames>(\n options?: StandardLogOptions<N>\n): { store: LogStore, standardLog: StandardLog<N> } {\n const store = createLogStore(required({ logLevel: logLevels.info }, options))\n\n return {\n store,\n standardLog: {\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 return store.loggers[id] = createLogger([store, id, options], { ssf: this.getLogger, ...meta }) as any\n }\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