standard-log 8.0.1 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (613) hide show
  1. package/README.md +57 -133
  2. package/{esm/console/createConsoleLogReporter.d.ts → cjs/console.d.ts} +5 -5
  3. package/cjs/console.d.ts.map +1 -0
  4. package/cjs/console.js +76 -0
  5. package/cjs/console.js.map +1 -0
  6. package/cjs/console.spec.d.ts +2 -0
  7. package/cjs/console.spec.d.ts.map +1 -0
  8. package/cjs/{console/createConsoleLogReporter.spec.js → console.spec.js} +50 -68
  9. package/cjs/console.spec.js.map +1 -0
  10. package/cjs/errors.d.ts +0 -10
  11. package/cjs/errors.d.ts.map +1 -1
  12. package/cjs/errors.js +1 -43
  13. package/cjs/errors.js.map +1 -1
  14. package/cjs/formatter.d.ts +6 -0
  15. package/cjs/formatter.d.ts.map +1 -0
  16. package/cjs/formatter.js +46 -0
  17. package/cjs/formatter.js.map +1 -0
  18. package/cjs/formatter.spec.d.ts +2 -0
  19. package/cjs/formatter.spec.d.ts.map +1 -0
  20. package/cjs/formatter.spec.js +32 -0
  21. package/cjs/formatter.spec.js.map +1 -0
  22. package/cjs/index.d.ts +5 -14
  23. package/cjs/index.d.ts.map +1 -1
  24. package/cjs/index.js +5 -14
  25. package/cjs/index.js.map +1 -1
  26. package/cjs/logLevels.d.ts +60 -0
  27. package/cjs/logLevels.d.ts.map +1 -0
  28. package/cjs/logLevels.js +87 -0
  29. package/cjs/logLevels.js.map +1 -0
  30. package/cjs/logStore.d.ts +20 -0
  31. package/cjs/logStore.d.ts.map +1 -0
  32. package/cjs/logStore.js +44 -0
  33. package/cjs/logStore.js.map +1 -0
  34. package/cjs/logStore.spec.d.ts +2 -0
  35. package/cjs/logStore.spec.d.ts.map +1 -0
  36. package/cjs/logStore.spec.js +93 -0
  37. package/cjs/logStore.spec.js.map +1 -0
  38. package/cjs/logger.d.ts +6 -0
  39. package/cjs/logger.d.ts.map +1 -0
  40. package/cjs/logger.js +97 -0
  41. package/cjs/logger.js.map +1 -0
  42. package/{esm/memory/MemoryLogReporter.d.ts → cjs/memory.d.ts} +2 -2
  43. package/cjs/memory.d.ts.map +1 -0
  44. package/cjs/memory.js +39 -0
  45. package/cjs/memory.js.map +1 -0
  46. package/cjs/memory.spec.d.ts +2 -0
  47. package/cjs/memory.spec.d.ts.map +1 -0
  48. package/cjs/memory.spec.js +115 -0
  49. package/cjs/memory.spec.js.map +1 -0
  50. package/cjs/package.json +1 -3
  51. package/cjs/platform.browser.d.ts +7 -0
  52. package/cjs/platform.browser.d.ts.map +1 -0
  53. package/cjs/platform.browser.js +11 -0
  54. package/cjs/platform.browser.js.map +1 -0
  55. package/cjs/platform.d.ts +8 -0
  56. package/cjs/platform.d.ts.map +1 -0
  57. package/cjs/platform.js +26 -0
  58. package/cjs/platform.js.map +1 -0
  59. package/cjs/platform.spec.d.ts +2 -0
  60. package/cjs/platform.spec.d.ts.map +1 -0
  61. package/cjs/platform.spec.js +22 -0
  62. package/cjs/platform.spec.js.map +1 -0
  63. package/cjs/standardLog.d.ts +21 -0
  64. package/cjs/standardLog.d.ts.map +1 -0
  65. package/cjs/standardLog.js +59 -0
  66. package/cjs/standardLog.js.map +1 -0
  67. package/cjs/standardLog.spec.d.ts +2 -0
  68. package/cjs/standardLog.spec.d.ts.map +1 -0
  69. package/cjs/standardLog.spec.js +536 -0
  70. package/cjs/standardLog.spec.js.map +1 -0
  71. package/cjs/testUtil.d.ts +7 -5
  72. package/cjs/testUtil.d.ts.map +1 -1
  73. package/cjs/testUtil.js +11 -14
  74. package/cjs/testUtil.js.map +1 -1
  75. package/cjs/types.d.ts +33 -24
  76. package/cjs/types.d.ts.map +1 -1
  77. package/cjs/types.js.map +1 -1
  78. package/dist/standard-log.es5.js +324 -1078
  79. package/dist/standard-log.es5.js.gz +0 -0
  80. package/dist/standard-log.es5.js.map +1 -1
  81. package/dist/standard-log.es5.js.map.gz +0 -0
  82. package/dist/standard-log.esm.js +307 -1145
  83. package/dist/standard-log.esm.js.gz +0 -0
  84. package/dist/standard-log.esm.js.map +1 -1
  85. package/dist/standard-log.esm.js.map.gz +0 -0
  86. package/{cjs/console/createConsoleLogReporter.d.ts → esm/console.d.ts} +5 -5
  87. package/esm/console.d.ts.map +1 -0
  88. package/esm/{console/polyfilledConsole.js → console.js} +36 -4
  89. package/esm/console.js.map +1 -0
  90. package/esm/console.spec.d.ts +2 -0
  91. package/esm/console.spec.d.ts.map +1 -0
  92. package/esm/{console/createConsoleLogReporter.spec.js → console.spec.js} +50 -65
  93. package/esm/console.spec.js.map +1 -0
  94. package/esm/errors.d.ts +0 -10
  95. package/esm/errors.d.ts.map +1 -1
  96. package/esm/errors.js +0 -34
  97. package/esm/errors.js.map +1 -1
  98. package/esm/formatter.d.ts +6 -0
  99. package/esm/formatter.d.ts.map +1 -0
  100. package/esm/{formatter/createTimestampFormatter.js → formatter.js} +10 -2
  101. package/esm/formatter.js.map +1 -0
  102. package/esm/formatter.spec.d.ts +2 -0
  103. package/esm/formatter.spec.d.ts.map +1 -0
  104. package/esm/formatter.spec.js +30 -0
  105. package/esm/formatter.spec.js.map +1 -0
  106. package/esm/index.d.ts +5 -14
  107. package/esm/index.d.ts.map +1 -1
  108. package/esm/index.js +5 -14
  109. package/esm/index.js.map +1 -1
  110. package/esm/logLevels.d.ts +60 -0
  111. package/esm/logLevels.d.ts.map +1 -0
  112. package/esm/{logLevel.js → logLevels.js} +29 -3
  113. package/esm/logLevels.js.map +1 -0
  114. package/esm/logStore.d.ts +20 -0
  115. package/esm/logStore.d.ts.map +1 -0
  116. package/esm/logStore.js +37 -0
  117. package/esm/logStore.js.map +1 -0
  118. package/esm/logStore.spec.d.ts +2 -0
  119. package/esm/logStore.spec.d.ts.map +1 -0
  120. package/esm/logStore.spec.js +93 -0
  121. package/esm/logStore.spec.js.map +1 -0
  122. package/esm/logger.d.ts +6 -0
  123. package/esm/logger.d.ts.map +1 -0
  124. package/esm/logger.js +74 -0
  125. package/esm/logger.js.map +1 -0
  126. package/{cjs/memory/MemoryLogReporter.d.ts → esm/memory.d.ts} +2 -2
  127. package/esm/memory.d.ts.map +1 -0
  128. package/esm/memory.js +34 -0
  129. package/esm/memory.js.map +1 -0
  130. package/esm/memory.spec.d.ts +2 -0
  131. package/esm/memory.spec.d.ts.map +1 -0
  132. package/esm/memory.spec.js +110 -0
  133. package/esm/memory.spec.js.map +1 -0
  134. package/esm/platform.browser.d.ts +7 -0
  135. package/esm/platform.browser.d.ts.map +1 -0
  136. package/esm/platform.browser.js +6 -0
  137. package/esm/platform.browser.js.map +1 -0
  138. package/esm/platform.d.ts +8 -0
  139. package/esm/platform.d.ts.map +1 -0
  140. package/esm/platform.js +20 -0
  141. package/esm/platform.js.map +1 -0
  142. package/esm/platform.spec.d.ts +2 -0
  143. package/esm/platform.spec.d.ts.map +1 -0
  144. package/esm/{console/semverGt.spec.js → platform.spec.js} +2 -2
  145. package/esm/platform.spec.js.map +1 -0
  146. package/esm/standardLog.d.ts +21 -0
  147. package/esm/standardLog.d.ts.map +1 -0
  148. package/esm/standardLog.js +36 -0
  149. package/esm/standardLog.js.map +1 -0
  150. package/esm/standardLog.spec.d.ts +2 -0
  151. package/esm/standardLog.spec.d.ts.map +1 -0
  152. package/esm/standardLog.spec.js +434 -0
  153. package/esm/standardLog.spec.js.map +1 -0
  154. package/esm/testUtil.d.ts +7 -5
  155. package/esm/testUtil.d.ts.map +1 -1
  156. package/esm/testUtil.js +8 -12
  157. package/esm/testUtil.js.map +1 -1
  158. package/esm/types.d.ts +33 -24
  159. package/esm/types.d.ts.map +1 -1
  160. package/esm/types.js.map +1 -1
  161. package/package.json +10 -19
  162. package/ts/console.ts +72 -0
  163. package/ts/errors.ts +0 -12
  164. package/ts/{formatter/createTimestampFormatter.ts → formatter.ts} +12 -1
  165. package/ts/index.ts +5 -14
  166. package/ts/{logLevel.ts → logLevels.ts} +20 -3
  167. package/ts/logStore.ts +52 -0
  168. package/ts/logger.ts +85 -0
  169. package/ts/memory.ts +47 -0
  170. package/ts/platform.browser.ts +8 -0
  171. package/ts/platform.ts +25 -0
  172. package/ts/standardLog.ts +54 -0
  173. package/ts/types.ts +39 -30
  174. package/cjs/LogEntry.d.ts +0 -7
  175. package/cjs/LogEntry.d.ts.map +0 -1
  176. package/cjs/LogEntry.js +0 -3
  177. package/cjs/LogEntry.js.map +0 -1
  178. package/cjs/captureLogs.d.ts +0 -4
  179. package/cjs/captureLogs.d.ts.map +0 -1
  180. package/cjs/captureLogs.js +0 -33
  181. package/cjs/captureLogs.js.map +0 -1
  182. package/cjs/captureLogs.spec.d.ts +0 -2
  183. package/cjs/captureLogs.spec.d.ts.map +0 -1
  184. package/cjs/captureLogs.spec.js +0 -117
  185. package/cjs/captureLogs.spec.js.map +0 -1
  186. package/cjs/config.d.ts +0 -12
  187. package/cjs/config.d.ts.map +0 -1
  188. package/cjs/config.js +0 -59
  189. package/cjs/config.js.map +0 -1
  190. package/cjs/config.spec.d.ts +0 -2
  191. package/cjs/config.spec.d.ts.map +0 -1
  192. package/cjs/config.spec.js +0 -72
  193. package/cjs/config.spec.js.map +0 -1
  194. package/cjs/configForTest.d.ts +0 -5
  195. package/cjs/configForTest.d.ts.map +0 -1
  196. package/cjs/configForTest.js +0 -18
  197. package/cjs/configForTest.js.map +0 -1
  198. package/cjs/configForTest.spec.d.ts +0 -2
  199. package/cjs/configForTest.spec.d.ts.map +0 -1
  200. package/cjs/configForTest.spec.js +0 -17
  201. package/cjs/configForTest.spec.js.map +0 -1
  202. package/cjs/console/createConsoleLogReporter.d.ts.map +0 -1
  203. package/cjs/console/createConsoleLogReporter.js +0 -42
  204. package/cjs/console/createConsoleLogReporter.js.map +0 -1
  205. package/cjs/console/createConsoleLogReporter.spec.d.ts +0 -2
  206. package/cjs/console/createConsoleLogReporter.spec.d.ts.map +0 -1
  207. package/cjs/console/createConsoleLogReporter.spec.js.map +0 -1
  208. package/cjs/console/index.d.ts +0 -4
  209. package/cjs/console/index.d.ts.map +0 -1
  210. package/cjs/console/index.js +0 -20
  211. package/cjs/console/index.js.map +0 -1
  212. package/cjs/console/isConsoleDebugAvailable.d.ts +0 -2
  213. package/cjs/console/isConsoleDebugAvailable.d.ts.map +0 -1
  214. package/cjs/console/isConsoleDebugAvailable.js +0 -20
  215. package/cjs/console/isConsoleDebugAvailable.js.map +0 -1
  216. package/cjs/console/polyfilledConsole.d.ts +0 -7
  217. package/cjs/console/polyfilledConsole.d.ts.map +0 -1
  218. package/cjs/console/polyfilledConsole.js +0 -41
  219. package/cjs/console/polyfilledConsole.js.map +0 -1
  220. package/cjs/console/semverGt.d.ts +0 -2
  221. package/cjs/console/semverGt.d.ts.map +0 -1
  222. package/cjs/console/semverGt.js +0 -13
  223. package/cjs/console/semverGt.js.map +0 -1
  224. package/cjs/console/semverGt.spec.d.ts +0 -2
  225. package/cjs/console/semverGt.spec.d.ts.map +0 -1
  226. package/cjs/console/semverGt.spec.js +0 -22
  227. package/cjs/console/semverGt.spec.js.map +0 -1
  228. package/cjs/console/toConsoleMethod.d.ts +0 -2
  229. package/cjs/console/toConsoleMethod.d.ts.map +0 -1
  230. package/cjs/console/toConsoleMethod.js +0 -22
  231. package/cjs/console/toConsoleMethod.js.map +0 -1
  232. package/cjs/console/types.d.ts +0 -3
  233. package/cjs/console/types.d.ts.map +0 -1
  234. package/cjs/console/types.js +0 -3
  235. package/cjs/console/types.js.map +0 -1
  236. package/cjs/customLogLevel.d.ts +0 -11
  237. package/cjs/customLogLevel.d.ts.map +0 -1
  238. package/cjs/customLogLevel.js +0 -38
  239. package/cjs/customLogLevel.js.map +0 -1
  240. package/cjs/customLogLevel.spec.d.ts +0 -2
  241. package/cjs/customLogLevel.spec.d.ts.map +0 -1
  242. package/cjs/customLogLevel.spec.js +0 -37
  243. package/cjs/customLogLevel.spec.js.map +0 -1
  244. package/cjs/formatter/createTimestampFormatter.d.ts +0 -3
  245. package/cjs/formatter/createTimestampFormatter.d.ts.map +0 -1
  246. package/cjs/formatter/createTimestampFormatter.js +0 -26
  247. package/cjs/formatter/createTimestampFormatter.js.map +0 -1
  248. package/cjs/formatter/createTimestampFormatter.spec.d.ts +0 -2
  249. package/cjs/formatter/createTimestampFormatter.spec.d.ts.map +0 -1
  250. package/cjs/formatter/createTimestampFormatter.spec.js +0 -23
  251. package/cjs/formatter/createTimestampFormatter.spec.js.map +0 -1
  252. package/cjs/formatter/formatLogLevel.d.ts +0 -2
  253. package/cjs/formatter/formatLogLevel.d.ts.map +0 -1
  254. package/cjs/formatter/formatLogLevel.js +0 -10
  255. package/cjs/formatter/formatLogLevel.js.map +0 -1
  256. package/cjs/formatter/index.d.ts +0 -4
  257. package/cjs/formatter/index.d.ts.map +0 -1
  258. package/cjs/formatter/index.js +0 -20
  259. package/cjs/formatter/index.js.map +0 -1
  260. package/cjs/formatter/plainLogFormatter.d.ts +0 -3
  261. package/cjs/formatter/plainLogFormatter.d.ts.map +0 -1
  262. package/cjs/formatter/plainLogFormatter.js +0 -19
  263. package/cjs/formatter/plainLogFormatter.js.map +0 -1
  264. package/cjs/formatter/plainLogFormatter.spec.d.ts +0 -2
  265. package/cjs/formatter/plainLogFormatter.spec.d.ts.map +0 -1
  266. package/cjs/formatter/plainLogFormatter.spec.js +0 -9
  267. package/cjs/formatter/plainLogFormatter.spec.js.map +0 -1
  268. package/cjs/getDefaultReporter.browser.d.ts +0 -2
  269. package/cjs/getDefaultReporter.browser.d.ts.map +0 -1
  270. package/cjs/getDefaultReporter.browser.js +0 -15
  271. package/cjs/getDefaultReporter.browser.js.map +0 -1
  272. package/cjs/getDefaultReporter.d.ts +0 -2
  273. package/cjs/getDefaultReporter.d.ts.map +0 -1
  274. package/cjs/getDefaultReporter.js +0 -19
  275. package/cjs/getDefaultReporter.js.map +0 -1
  276. package/cjs/getLogModeFromEnvironment.browser.d.ts +0 -3
  277. package/cjs/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  278. package/cjs/getLogModeFromEnvironment.browser.js +0 -9
  279. package/cjs/getLogModeFromEnvironment.browser.js.map +0 -1
  280. package/cjs/getLogModeFromEnvironment.d.ts +0 -3
  281. package/cjs/getLogModeFromEnvironment.d.ts.map +0 -1
  282. package/cjs/getLogModeFromEnvironment.js +0 -17
  283. package/cjs/getLogModeFromEnvironment.js.map +0 -1
  284. package/cjs/getLogModeFromEnvironment.spec.d.ts +0 -2
  285. package/cjs/getLogModeFromEnvironment.spec.d.ts.map +0 -1
  286. package/cjs/getLogModeFromEnvironment.spec.js +0 -25
  287. package/cjs/getLogModeFromEnvironment.spec.js.map +0 -1
  288. package/cjs/getLogger.d.ts +0 -9
  289. package/cjs/getLogger.d.ts.map +0 -1
  290. package/cjs/getLogger.js +0 -103
  291. package/cjs/getLogger.js.map +0 -1
  292. package/cjs/getLogger.spec.d.ts +0 -2
  293. package/cjs/getLogger.spec.d.ts.map +0 -1
  294. package/cjs/getLogger.spec.js +0 -485
  295. package/cjs/getLogger.spec.js.map +0 -1
  296. package/cjs/getLoggers.d.ts +0 -7
  297. package/cjs/getLoggers.d.ts.map +0 -1
  298. package/cjs/getLoggers.js +0 -15
  299. package/cjs/getLoggers.js.map +0 -1
  300. package/cjs/logLevel.d.ts +0 -106
  301. package/cjs/logLevel.d.ts.map +0 -1
  302. package/cjs/logLevel.js +0 -59
  303. package/cjs/logLevel.js.map +0 -1
  304. package/cjs/logLevel.spec.d.ts +0 -2
  305. package/cjs/logLevel.spec.d.ts.map +0 -1
  306. package/cjs/logLevel.spec.js +0 -195
  307. package/cjs/logLevel.spec.js.map +0 -1
  308. package/cjs/logLevelFn.d.ts +0 -20
  309. package/cjs/logLevelFn.d.ts.map +0 -1
  310. package/cjs/logLevelFn.js +0 -76
  311. package/cjs/logLevelFn.js.map +0 -1
  312. package/cjs/logReporter.d.ts +0 -7
  313. package/cjs/logReporter.d.ts.map +0 -1
  314. package/cjs/logReporter.js +0 -29
  315. package/cjs/logReporter.js.map +0 -1
  316. package/cjs/logReporter.spec.d.ts +0 -2
  317. package/cjs/logReporter.spec.d.ts.map +0 -1
  318. package/cjs/logReporter.spec.js +0 -98
  319. package/cjs/logReporter.spec.js.map +0 -1
  320. package/cjs/logReporterInternal.d.ts +0 -3
  321. package/cjs/logReporterInternal.d.ts.map +0 -1
  322. package/cjs/logReporterInternal.js +0 -23
  323. package/cjs/logReporterInternal.js.map +0 -1
  324. package/cjs/memory/MemoryLogReporter.d.ts.map +0 -1
  325. package/cjs/memory/MemoryLogReporter.js +0 -56
  326. package/cjs/memory/MemoryLogReporter.js.map +0 -1
  327. package/cjs/memory/MemoryLogReporter.spec.d.ts +0 -2
  328. package/cjs/memory/MemoryLogReporter.spec.d.ts.map +0 -1
  329. package/cjs/memory/MemoryLogReporter.spec.js +0 -124
  330. package/cjs/memory/MemoryLogReporter.spec.js.map +0 -1
  331. package/cjs/memory/index.d.ts +0 -3
  332. package/cjs/memory/index.d.ts.map +0 -1
  333. package/cjs/memory/index.js +0 -19
  334. package/cjs/memory/index.js.map +0 -1
  335. package/cjs/memory/logEntriesToString.d.ts +0 -3
  336. package/cjs/memory/logEntriesToString.d.ts.map +0 -1
  337. package/cjs/memory/logEntriesToString.js +0 -10
  338. package/cjs/memory/logEntriesToString.js.map +0 -1
  339. package/cjs/memory/logEntriesToString.spec.d.ts +0 -2
  340. package/cjs/memory/logEntriesToString.spec.d.ts.map +0 -1
  341. package/cjs/memory/logEntriesToString.spec.js +0 -36
  342. package/cjs/memory/logEntriesToString.spec.js.map +0 -1
  343. package/cjs/memory/toInspectStringForObject.d.ts +0 -3
  344. package/cjs/memory/toInspectStringForObject.d.ts.map +0 -1
  345. package/cjs/memory/toInspectStringForObject.js +0 -17
  346. package/cjs/memory/toInspectStringForObject.js.map +0 -1
  347. package/cjs/shouldLog.d.ts +0 -8
  348. package/cjs/shouldLog.d.ts.map +0 -1
  349. package/cjs/shouldLog.js +0 -14
  350. package/cjs/shouldLog.js.map +0 -1
  351. package/cjs/store.d.ts +0 -3
  352. package/cjs/store.d.ts.map +0 -1
  353. package/cjs/store.js +0 -27
  354. package/cjs/store.js.map +0 -1
  355. package/cjs/suppressLogs.d.ts +0 -6
  356. package/cjs/suppressLogs.d.ts.map +0 -1
  357. package/cjs/suppressLogs.js +0 -17
  358. package/cjs/suppressLogs.js.map +0 -1
  359. package/cjs/suppressLogs.spec.d.ts +0 -2
  360. package/cjs/suppressLogs.spec.d.ts.map +0 -1
  361. package/cjs/suppressLogs.spec.js +0 -31
  362. package/cjs/suppressLogs.spec.js.map +0 -1
  363. package/cjs/typesInternal.d.ts +0 -20
  364. package/cjs/typesInternal.d.ts.map +0 -1
  365. package/cjs/typesInternal.js +0 -3
  366. package/cjs/typesInternal.js.map +0 -1
  367. package/cjs/utils.d.ts +0 -6
  368. package/cjs/utils.d.ts.map +0 -1
  369. package/cjs/utils.js +0 -15
  370. package/cjs/utils.js.map +0 -1
  371. package/cjs/writeToReporters.d.ts +0 -6
  372. package/cjs/writeToReporters.d.ts.map +0 -1
  373. package/cjs/writeToReporters.js +0 -22
  374. package/cjs/writeToReporters.js.map +0 -1
  375. package/cjs/writeToReporters.spec.d.ts +0 -2
  376. package/cjs/writeToReporters.spec.d.ts.map +0 -1
  377. package/cjs/writeToReporters.spec.js +0 -59
  378. package/cjs/writeToReporters.spec.js.map +0 -1
  379. package/esm/LogEntry.d.ts +0 -7
  380. package/esm/LogEntry.d.ts.map +0 -1
  381. package/esm/LogEntry.js +0 -2
  382. package/esm/LogEntry.js.map +0 -1
  383. package/esm/captureLogs.d.ts +0 -4
  384. package/esm/captureLogs.d.ts.map +0 -1
  385. package/esm/captureLogs.js +0 -29
  386. package/esm/captureLogs.js.map +0 -1
  387. package/esm/captureLogs.spec.d.ts +0 -2
  388. package/esm/captureLogs.spec.d.ts.map +0 -1
  389. package/esm/captureLogs.spec.js +0 -45
  390. package/esm/captureLogs.spec.js.map +0 -1
  391. package/esm/config.d.ts +0 -12
  392. package/esm/config.d.ts.map +0 -1
  393. package/esm/config.js +0 -44
  394. package/esm/config.js.map +0 -1
  395. package/esm/config.spec.d.ts +0 -2
  396. package/esm/config.spec.d.ts.map +0 -1
  397. package/esm/config.spec.js +0 -67
  398. package/esm/config.spec.js.map +0 -1
  399. package/esm/configForTest.d.ts +0 -5
  400. package/esm/configForTest.d.ts.map +0 -1
  401. package/esm/configForTest.js +0 -14
  402. package/esm/configForTest.js.map +0 -1
  403. package/esm/configForTest.spec.d.ts +0 -2
  404. package/esm/configForTest.spec.d.ts.map +0 -1
  405. package/esm/configForTest.spec.js +0 -15
  406. package/esm/configForTest.spec.js.map +0 -1
  407. package/esm/console/createConsoleLogReporter.d.ts.map +0 -1
  408. package/esm/console/createConsoleLogReporter.js +0 -37
  409. package/esm/console/createConsoleLogReporter.js.map +0 -1
  410. package/esm/console/createConsoleLogReporter.spec.d.ts +0 -2
  411. package/esm/console/createConsoleLogReporter.spec.d.ts.map +0 -1
  412. package/esm/console/createConsoleLogReporter.spec.js.map +0 -1
  413. package/esm/console/index.d.ts +0 -4
  414. package/esm/console/index.d.ts.map +0 -1
  415. package/esm/console/index.js +0 -4
  416. package/esm/console/index.js.map +0 -1
  417. package/esm/console/isConsoleDebugAvailable.d.ts +0 -2
  418. package/esm/console/isConsoleDebugAvailable.d.ts.map +0 -1
  419. package/esm/console/isConsoleDebugAvailable.js +0 -13
  420. package/esm/console/isConsoleDebugAvailable.js.map +0 -1
  421. package/esm/console/polyfilledConsole.d.ts +0 -7
  422. package/esm/console/polyfilledConsole.d.ts.map +0 -1
  423. package/esm/console/polyfilledConsole.js.map +0 -1
  424. package/esm/console/semverGt.d.ts +0 -2
  425. package/esm/console/semverGt.d.ts.map +0 -1
  426. package/esm/console/semverGt.js +0 -9
  427. package/esm/console/semverGt.js.map +0 -1
  428. package/esm/console/semverGt.spec.d.ts +0 -2
  429. package/esm/console/semverGt.spec.d.ts.map +0 -1
  430. package/esm/console/semverGt.spec.js.map +0 -1
  431. package/esm/console/toConsoleMethod.d.ts +0 -2
  432. package/esm/console/toConsoleMethod.d.ts.map +0 -1
  433. package/esm/console/toConsoleMethod.js +0 -18
  434. package/esm/console/toConsoleMethod.js.map +0 -1
  435. package/esm/console/types.d.ts +0 -3
  436. package/esm/console/types.d.ts.map +0 -1
  437. package/esm/console/types.js +0 -2
  438. package/esm/console/types.js.map +0 -1
  439. package/esm/customLogLevel.d.ts +0 -11
  440. package/esm/customLogLevel.d.ts.map +0 -1
  441. package/esm/customLogLevel.js +0 -30
  442. package/esm/customLogLevel.js.map +0 -1
  443. package/esm/customLogLevel.spec.d.ts +0 -2
  444. package/esm/customLogLevel.spec.d.ts.map +0 -1
  445. package/esm/customLogLevel.spec.js +0 -32
  446. package/esm/customLogLevel.spec.js.map +0 -1
  447. package/esm/formatter/createTimestampFormatter.d.ts +0 -3
  448. package/esm/formatter/createTimestampFormatter.d.ts.map +0 -1
  449. package/esm/formatter/createTimestampFormatter.js.map +0 -1
  450. package/esm/formatter/createTimestampFormatter.spec.d.ts +0 -2
  451. package/esm/formatter/createTimestampFormatter.spec.d.ts.map +0 -1
  452. package/esm/formatter/createTimestampFormatter.spec.js +0 -21
  453. package/esm/formatter/createTimestampFormatter.spec.js.map +0 -1
  454. package/esm/formatter/formatLogLevel.d.ts +0 -2
  455. package/esm/formatter/formatLogLevel.d.ts.map +0 -1
  456. package/esm/formatter/formatLogLevel.js +0 -6
  457. package/esm/formatter/formatLogLevel.js.map +0 -1
  458. package/esm/formatter/index.d.ts +0 -4
  459. package/esm/formatter/index.d.ts.map +0 -1
  460. package/esm/formatter/index.js +0 -4
  461. package/esm/formatter/index.js.map +0 -1
  462. package/esm/formatter/plainLogFormatter.d.ts +0 -3
  463. package/esm/formatter/plainLogFormatter.d.ts.map +0 -1
  464. package/esm/formatter/plainLogFormatter.js +0 -5
  465. package/esm/formatter/plainLogFormatter.js.map +0 -1
  466. package/esm/formatter/plainLogFormatter.spec.d.ts +0 -2
  467. package/esm/formatter/plainLogFormatter.spec.d.ts.map +0 -1
  468. package/esm/formatter/plainLogFormatter.spec.js +0 -7
  469. package/esm/formatter/plainLogFormatter.spec.js.map +0 -1
  470. package/esm/getDefaultReporter.browser.d.ts +0 -2
  471. package/esm/getDefaultReporter.browser.d.ts.map +0 -1
  472. package/esm/getDefaultReporter.browser.js +0 -11
  473. package/esm/getDefaultReporter.browser.js.map +0 -1
  474. package/esm/getDefaultReporter.d.ts +0 -2
  475. package/esm/getDefaultReporter.d.ts.map +0 -1
  476. package/esm/getDefaultReporter.js +0 -15
  477. package/esm/getDefaultReporter.js.map +0 -1
  478. package/esm/getLogModeFromEnvironment.browser.d.ts +0 -3
  479. package/esm/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  480. package/esm/getLogModeFromEnvironment.browser.js +0 -5
  481. package/esm/getLogModeFromEnvironment.browser.js.map +0 -1
  482. package/esm/getLogModeFromEnvironment.d.ts +0 -3
  483. package/esm/getLogModeFromEnvironment.d.ts.map +0 -1
  484. package/esm/getLogModeFromEnvironment.js +0 -13
  485. package/esm/getLogModeFromEnvironment.js.map +0 -1
  486. package/esm/getLogModeFromEnvironment.spec.d.ts +0 -2
  487. package/esm/getLogModeFromEnvironment.spec.d.ts.map +0 -1
  488. package/esm/getLogModeFromEnvironment.spec.js +0 -20
  489. package/esm/getLogModeFromEnvironment.spec.js.map +0 -1
  490. package/esm/getLogger.d.ts +0 -9
  491. package/esm/getLogger.d.ts.map +0 -1
  492. package/esm/getLogger.js +0 -78
  493. package/esm/getLogger.js.map +0 -1
  494. package/esm/getLogger.spec.d.ts +0 -2
  495. package/esm/getLogger.spec.d.ts.map +0 -1
  496. package/esm/getLogger.spec.js +0 -385
  497. package/esm/getLogger.spec.js.map +0 -1
  498. package/esm/getLoggers.d.ts +0 -7
  499. package/esm/getLoggers.d.ts.map +0 -1
  500. package/esm/getLoggers.js +0 -11
  501. package/esm/getLoggers.js.map +0 -1
  502. package/esm/logLevel.d.ts +0 -106
  503. package/esm/logLevel.d.ts.map +0 -1
  504. package/esm/logLevel.js.map +0 -1
  505. package/esm/logLevel.spec.d.ts +0 -2
  506. package/esm/logLevel.spec.d.ts.map +0 -1
  507. package/esm/logLevel.spec.js +0 -148
  508. package/esm/logLevel.spec.js.map +0 -1
  509. package/esm/logLevelFn.d.ts +0 -20
  510. package/esm/logLevelFn.d.ts.map +0 -1
  511. package/esm/logLevelFn.js +0 -67
  512. package/esm/logLevelFn.js.map +0 -1
  513. package/esm/logReporter.d.ts +0 -7
  514. package/esm/logReporter.d.ts.map +0 -1
  515. package/esm/logReporter.js +0 -21
  516. package/esm/logReporter.js.map +0 -1
  517. package/esm/logReporter.spec.d.ts +0 -2
  518. package/esm/logReporter.spec.d.ts.map +0 -1
  519. package/esm/logReporter.spec.js +0 -93
  520. package/esm/logReporter.spec.js.map +0 -1
  521. package/esm/logReporterInternal.d.ts +0 -3
  522. package/esm/logReporterInternal.d.ts.map +0 -1
  523. package/esm/logReporterInternal.js +0 -19
  524. package/esm/logReporterInternal.js.map +0 -1
  525. package/esm/memory/MemoryLogReporter.d.ts.map +0 -1
  526. package/esm/memory/MemoryLogReporter.js +0 -51
  527. package/esm/memory/MemoryLogReporter.js.map +0 -1
  528. package/esm/memory/MemoryLogReporter.spec.d.ts +0 -2
  529. package/esm/memory/MemoryLogReporter.spec.d.ts.map +0 -1
  530. package/esm/memory/MemoryLogReporter.spec.js +0 -111
  531. package/esm/memory/MemoryLogReporter.spec.js.map +0 -1
  532. package/esm/memory/index.d.ts +0 -3
  533. package/esm/memory/index.d.ts.map +0 -1
  534. package/esm/memory/index.js +0 -3
  535. package/esm/memory/index.js.map +0 -1
  536. package/esm/memory/logEntriesToString.d.ts +0 -3
  537. package/esm/memory/logEntriesToString.d.ts.map +0 -1
  538. package/esm/memory/logEntriesToString.js +0 -6
  539. package/esm/memory/logEntriesToString.js.map +0 -1
  540. package/esm/memory/logEntriesToString.spec.d.ts +0 -2
  541. package/esm/memory/logEntriesToString.spec.d.ts.map +0 -1
  542. package/esm/memory/logEntriesToString.spec.js +0 -42
  543. package/esm/memory/logEntriesToString.spec.js.map +0 -1
  544. package/esm/memory/toInspectStringForObject.d.ts +0 -3
  545. package/esm/memory/toInspectStringForObject.d.ts.map +0 -1
  546. package/esm/memory/toInspectStringForObject.js +0 -11
  547. package/esm/memory/toInspectStringForObject.js.map +0 -1
  548. package/esm/shouldLog.d.ts +0 -8
  549. package/esm/shouldLog.d.ts.map +0 -1
  550. package/esm/shouldLog.js +0 -10
  551. package/esm/shouldLog.js.map +0 -1
  552. package/esm/store.d.ts +0 -3
  553. package/esm/store.d.ts.map +0 -1
  554. package/esm/store.js +0 -24
  555. package/esm/store.js.map +0 -1
  556. package/esm/suppressLogs.d.ts +0 -6
  557. package/esm/suppressLogs.d.ts.map +0 -1
  558. package/esm/suppressLogs.js +0 -9
  559. package/esm/suppressLogs.js.map +0 -1
  560. package/esm/suppressLogs.spec.d.ts +0 -2
  561. package/esm/suppressLogs.spec.d.ts.map +0 -1
  562. package/esm/suppressLogs.spec.js +0 -29
  563. package/esm/suppressLogs.spec.js.map +0 -1
  564. package/esm/typesInternal.d.ts +0 -20
  565. package/esm/typesInternal.d.ts.map +0 -1
  566. package/esm/typesInternal.js +0 -2
  567. package/esm/typesInternal.js.map +0 -1
  568. package/esm/utils.d.ts +0 -6
  569. package/esm/utils.d.ts.map +0 -1
  570. package/esm/utils.js +0 -11
  571. package/esm/utils.js.map +0 -1
  572. package/esm/writeToReporters.d.ts +0 -6
  573. package/esm/writeToReporters.d.ts.map +0 -1
  574. package/esm/writeToReporters.js +0 -18
  575. package/esm/writeToReporters.js.map +0 -1
  576. package/esm/writeToReporters.spec.d.ts +0 -2
  577. package/esm/writeToReporters.spec.d.ts.map +0 -1
  578. package/esm/writeToReporters.spec.js +0 -9
  579. package/esm/writeToReporters.spec.js.map +0 -1
  580. package/ts/LogEntry.ts +0 -7
  581. package/ts/captureLogs.ts +0 -35
  582. package/ts/config.ts +0 -57
  583. package/ts/configForTest.ts +0 -16
  584. package/ts/console/createConsoleLogReporter.ts +0 -48
  585. package/ts/console/index.ts +0 -3
  586. package/ts/console/isConsoleDebugAvailable.ts +0 -11
  587. package/ts/console/polyfilledConsole.ts +0 -34
  588. package/ts/console/semverGt.ts +0 -9
  589. package/ts/console/toConsoleMethod.ts +0 -18
  590. package/ts/console/types.ts +0 -3
  591. package/ts/customLogLevel.ts +0 -35
  592. package/ts/formatter/formatLogLevel.ts +0 -6
  593. package/ts/formatter/index.ts +0 -3
  594. package/ts/formatter/plainLogFormatter.ts +0 -6
  595. package/ts/getDefaultReporter.browser.ts +0 -13
  596. package/ts/getDefaultReporter.ts +0 -15
  597. package/ts/getLogModeFromEnvironment.browser.ts +0 -6
  598. package/ts/getLogModeFromEnvironment.ts +0 -16
  599. package/ts/getLogger.ts +0 -92
  600. package/ts/getLoggers.ts +0 -12
  601. package/ts/logLevelFn.ts +0 -72
  602. package/ts/logReporter.ts +0 -26
  603. package/ts/logReporterInternal.ts +0 -18
  604. package/ts/memory/MemoryLogReporter.ts +0 -72
  605. package/ts/memory/index.ts +0 -2
  606. package/ts/memory/logEntriesToString.ts +0 -7
  607. package/ts/memory/toInspectStringForObject.ts +0 -13
  608. package/ts/shouldLog.ts +0 -11
  609. package/ts/store.ts +0 -25
  610. package/ts/suppressLogs.ts +0 -14
  611. package/ts/typesInternal.ts +0 -21
  612. package/ts/utils.ts +0 -11
  613. package/ts/writeToReporters.ts +0 -20
package/esm/types.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- export declare type LogMode = 'development' | 'production' | 'test';
2
- export declare type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck';
3
- export declare type LogMethod = (...args: any[]) => void;
4
- export declare type LogFunction = ((log: LogMethod) => void) | (() => string);
5
- export declare type LogEntry = {
6
- id: string;
7
- level: number;
8
- args: any[];
9
- timestamp: Date;
1
+ export declare type StandardLogOptions<CustomLevelNames extends string = string> = {
2
+ customLevels: Record<CustomLevelNames, number>;
3
+ logLevel: number;
4
+ reporters: LogReporter[];
10
5
  };
6
+ export interface LoggerOptions {
7
+ level?: number;
8
+ writeTo?: LogReporter | ReporterFilter;
9
+ }
11
10
  export declare type Logger<T extends string = LogMethodNames> = {
12
11
  readonly id: string;
13
12
  /**
@@ -22,17 +21,28 @@ export declare type Logger<T extends string = LogMethodNames> = {
22
21
  on(level: number | T, logFunction: LogFunction): void;
23
22
  /**
24
23
  * Write custom log entries.
25
- * This can be used along with `captureLogs()` to rewrite the logs at a later time.
26
24
  */
27
25
  write(entry: LogEntry): void;
28
26
  } & {
29
27
  [k in T]: LogMethod;
30
28
  };
29
+ /**
30
+ * Names of the standard log methods.
31
+ */
32
+ export declare type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck';
33
+ export declare type LogEntry = {
34
+ id: string;
35
+ level: number;
36
+ args: any[];
37
+ timestamp: Date;
38
+ };
39
+ export declare type LogMethod = (...args: any[]) => void;
40
+ export declare type LogFunction = ((log: LogMethod) => void) | (() => string);
31
41
  export declare type ReporterFilter = string | RegExp | ((reporterId: string) => boolean);
32
42
  /**
33
43
  * Formats a log entry.
34
44
  * Depends on the reporter, it can expect a different return type.
35
- * By default the return type is `any[]` which `console` accepts.
45
+ * By default the return type is `any[]` which the `console` accepts.
36
46
  */
37
47
  export declare type LogFormatter<T = any[]> = (entry: LogEntry) => T;
38
48
  /**
@@ -43,31 +53,24 @@ export declare type LogLevelEntry = {
43
53
  name: string;
44
54
  level: number;
45
55
  };
46
- export declare type LogLevelListener = (logLevelEntry: LogLevelEntry) => void;
47
- export declare type LogReporter<T = any> = {
48
- id: string;
56
+ export interface LogReporter<T = any> {
57
+ readonly id: string;
49
58
  /**
50
59
  * Specifies the formatter to be used by the reporter.
51
60
  * Using this you can customize how the reporter writes the log entry.
52
- * This is readonly in production mode.
53
61
  */
54
- formatter: LogFormatter<T>;
62
+ readonly formatter: LogFormatter<T>;
55
63
  /**
56
64
  * Specifies a filter to determine should the log be written.
57
- * This is readonly in production mode.
58
65
  */
59
- filter?: LogFilter;
66
+ readonly filter?: LogFilter;
60
67
  /**
61
68
  * Indicate if this is a console reporter.
62
69
  * There is only one console reporter can be present in the system.
63
- * If a new console reporter is added,
64
- * it will be used in place of the existing one.
65
- * However, existing filter will be carried over to ensure logs should not be shown remain not shown.
66
- * If the new reporter also contains a filter, they will be combined.
67
70
  */
68
- isConsoleReporter?: boolean;
71
+ readonly isConsoleReporter?: boolean;
69
72
  write(entry: LogEntry): void;
70
- };
73
+ }
71
74
  export declare type LogReporterOptions<T = any> = {
72
75
  id?: string;
73
76
  /**
@@ -81,4 +84,10 @@ export declare type LogReporterOptions<T = any> = {
81
84
  filter?: LogFilter;
82
85
  };
83
86
  export declare type LogLevel = number;
87
+ export interface ConsoleLike {
88
+ debug(...args: any[]): void;
89
+ info(...args: any[]): void;
90
+ warn(...args: any[]): void;
91
+ error(...args: any[]): void;
92
+ }
84
93
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"AACA,oBAAY,OAAO,GAAG,aAAa,GAAG,YAAY,GAAG,MAAM,CAAA;AAE3D,oBAAY,cAAc,GAAG,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAA;AACrI,oBAAY,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;AAChD,oBAAY,WAAW,GAAG,CAAC,CAAC,GAAG,EAAE,SAAS,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,CAAA;AAErE,oBAAY,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,SAAS,EAAE,IAAI,CAAA;CAChB,CAAA;AAED,oBAAY,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI;IACtD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IACtD;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC7B,GAAG;KACC,CAAC,IAAI,CAAC,GAAG,SAAS;CACpB,CAAA;AAEH,oBAAY,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAA;AAEhF;;;;GAIG;AACH,oBAAY,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAA;AAE5D;;GAEG;AACH,oBAAY,SAAS,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAA;AAEpD,oBAAY,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3D,oBAAY,gBAAgB,GAAG,CAAC,aAAa,EAAE,aAAa,KAAK,IAAI,CAAA;AAErE,oBAAY,WAAW,CAAC,CAAC,GAAG,GAAG,IAAI;IACjC,EAAE,EAAE,MAAM,CAAC;IACX;;;;OAIG;IACH,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC7B,CAAA;AAED,oBAAY,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB,CAAA;AAED,oBAAY,QAAQ,GAAG,MAAM,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB,CAAC,gBAAgB,SAAS,MAAM,GAAG,MAAM,IAAI;IACzE,YAAY,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,WAAW,EAAE,CAAA;CACzB,CAAA;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,WAAW,GAAG,cAAc,CAAA;CACvC;AAED,oBAAY,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI;IACtD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IACtD;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC7B,GAAG;KAAG,CAAC,IAAI,CAAC,GAAG,SAAS;CAAE,CAAA;AAE3B;;GAEG;AACH,oBAAY,cAAc,GAAG,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAA;AAErI,oBAAY,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IAEd,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,SAAS,EAAE,IAAI,CAAA;CAChB,CAAA;AAED,oBAAY,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;AAEhD,oBAAY,WAAW,GAAG,CAAC,CAAC,GAAG,EAAE,SAAS,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,CAAA;AAErE,oBAAY,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAA;AAEhF;;;;GAIG;AACH,oBAAY,YAAY,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAA;AAE5D;;GAEG;AACH,oBAAY,SAAS,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAA;AAEpD,oBAAY,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAE3D,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IACrC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC7B;AAED,oBAAY,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB,CAAA;AAED,oBAAY,QAAQ,GAAG,MAAM,CAAA;AAE7B,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC7B"}
package/esm/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["\nexport type LogMode = 'development' | 'production' | 'test'\n\nexport type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck'\nexport type LogMethod = (...args: any[]) => void\nexport type LogFunction = ((log: LogMethod) => void) | (() => string)\n\nexport type LogEntry = {\n id: string,\n level: number,\n // args instead of messages because it is `any[]` instead of `string[]`\n args: any[],\n timestamp: Date\n}\n\nexport type Logger<T extends string = LogMethodNames> = {\n readonly id: string,\n /**\n * Logger local log level.\n */\n level?: number,\n /**\n * Logs with an increment counter.\n * This is useful during debugging to check for steps executed.\n */\n count(...args: any[]): void,\n on(level: number | T, logFunction: LogFunction): void,\n /**\n * Write custom log entries.\n * This can be used along with `captureLogs()` to rewrite the logs at a later time.\n */\n write(entry: LogEntry): void\n} & {\n [k in T]: LogMethod\n }\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string, level: number }\n\nexport type LogLevelListener = (logLevelEntry: LogLevelEntry) => void\n\nexport type LogReporter<T = any> = {\n id: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n * This is readonly in production mode.\n */\n formatter: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n * This is readonly in production mode.\n */\n filter?: LogFilter,\n /**\n * Indicate if this is a console reporter.\n * There is only one console reporter can be present in the system.\n * If a new console reporter is added,\n * it will be used in place of the existing one.\n * However, existing filter will be carried over to ensure logs should not be shown remain not shown.\n * If the new reporter also contains a filter, they will be combined.\n */\n isConsoleReporter?: boolean,\n write(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n id?: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n formatter?: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n filter?: LogFilter\n}\n\nexport type LogLevel = number\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../ts/types.ts"],"names":[],"mappings":"","sourcesContent":["export type StandardLogOptions<CustomLevelNames extends string = string> = {\n customLevels: Record<CustomLevelNames, number>,\n logLevel: number,\n reporters: LogReporter[]\n}\n\nexport interface LoggerOptions {\n level?: number,\n writeTo?: LogReporter | ReporterFilter\n}\n\nexport type Logger<T extends string = LogMethodNames> = {\n readonly id: string,\n /**\n * Logger local log level.\n */\n level?: number,\n /**\n * Logs with an increment counter.\n * This is useful during debugging to check for steps executed.\n */\n count(...args: any[]): void,\n on(level: number | T, logFunction: LogFunction): void,\n /**\n * Write custom log entries.\n */\n write(entry: LogEntry): void\n} & { [k in T]: LogMethod }\n\n/**\n * Names of the standard log methods.\n */\nexport type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck'\n\nexport type LogEntry = {\n id: string,\n level: number,\n // args instead of messages because it is `any[]` instead of `string[]`\n args: any[],\n timestamp: Date\n}\n\nexport type LogMethod = (...args: any[]) => void\n\nexport type LogFunction = ((log: LogMethod) => void) | (() => string)\n\nexport type ReporterFilter = string | RegExp | ((reporterId: string) => boolean)\n\n/**\n * Formats a log entry.\n * Depends on the reporter, it can expect a different return type.\n * By default the return type is `any[]` which the `console` accepts.\n */\nexport type LogFormatter<T = any[]> = (entry: LogEntry) => T\n\n/**\n * Determines whether the entry should be written.\n */\nexport type LogFilter = (entry: LogEntry) => boolean\n\nexport type LogLevelEntry = { name: string, level: number }\n\nexport interface LogReporter<T = any> {\n readonly id: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n readonly formatter: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n readonly filter?: LogFilter,\n /**\n * Indicate if this is a console reporter.\n * There is only one console reporter can be present in the system.\n */\n readonly isConsoleReporter?: boolean,\n write(entry: LogEntry): void\n}\n\nexport type LogReporterOptions<T = any> = {\n id?: string,\n /**\n * Specifies the formatter to be used by the reporter.\n * Using this you can customize how the reporter writes the log entry.\n */\n formatter?: LogFormatter<T>,\n /**\n * Specifies a filter to determine should the log be written.\n */\n filter?: LogFilter\n}\n\nexport type LogLevel = number\n\nexport interface ConsoleLike {\n debug(...args: any[]): void,\n info(...args: any[]): void,\n warn(...args: any[]): void,\n error(...args: any[]): void,\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "standard-log",
3
- "version": "8.0.1",
3
+ "version": "9.0.0",
4
4
  "description": "The standard log library",
5
5
  "homepage": "https://github.com/unional/standard-log/tree/master/packages/log",
6
6
  "bugs": {
@@ -23,12 +23,9 @@
23
23
  },
24
24
  "main": "./cjs/index.js",
25
25
  "browser": {
26
- "./cjs/getDefaultReporter.js": "./cjs/getDefaultReporter.browser.js",
27
- "./cjs/getLogModeFromEnvironment.js": "./cjs/getLogModeFromEnvironment.browser.js",
28
- "./esm/getDefaultReporter.js": "./esm/getDefaultReporter.browser.js",
29
- "./esm/getLogModeFromEnvironment.js": "./esm/getLogModeFromEnvironment.browser.js",
30
- "./ts/getDefaultReporter.ts": "./ts/getDefaultReporter.browser.ts",
31
- "./ts/getLogModeFromEnvironment.ts": "./ts/getLogModeFromEnvironment.browser.ts"
26
+ "./cjs/platform.js": "./cjs/platform.browser.js",
27
+ "./esm/platform.js": "./esm/platform.browser.js",
28
+ "./ts/platform.js": "./ts/platform.browser.js"
32
29
  },
33
30
  "typings": "./cjs/index.d.ts",
34
31
  "files": [
@@ -48,7 +45,7 @@
48
45
  "bundle": "run-p bundle:es5 bundle:esm",
49
46
  "bundle:es5": "webpack -c ./webpack.es5.cjs",
50
47
  "bundle:esm": "webpack -c ./webpack.esm.cjs",
51
- "clean": "rimraf dist lib libm cjs esm tslib coverage .tsbuildinfo || true",
48
+ "clean": "rimraf cjs coverage dist esm lib libm tslib .tsbuildinfo && mkdir cjs && echo '{\"type\":\"commonjs\"}' > cjs/package.json || true",
52
49
  "coverage": "jest --coverage",
53
50
  "depcheck": "depcheck",
54
51
  "lint": "cross-env TIMING=1 eslint --ext=ts,js,cjs,mjs .",
@@ -58,42 +55,36 @@
58
55
  "watch": "jest --watch"
59
56
  },
60
57
  "dependencies": {
61
- "is-node": "^1.0.2",
62
- "iso-error": "^4.3.3",
58
+ "@just-func/types": "^0.2.0",
59
+ "iso-error": "^4.3.5",
63
60
  "ms": "^2.1.3",
64
- "tslib": "^2.4.0",
65
61
  "type-plus": "^4.10.0",
66
62
  "upper-case": "^2.0.2"
67
63
  },
68
64
  "devDependencies": {
69
65
  "@size-limit/preset-small-lib": "^7.0.8",
70
66
  "@types/ms": "^0.7.31",
67
+ "@types/ramda": "^0.28.13",
71
68
  "assertron": "^9.2.3",
72
69
  "compression-webpack-plugin": "^10.0.0",
73
70
  "cross-env": "^7.0.3",
74
- "delay": "^5.0.0",
75
71
  "depcheck": "^1.4.3",
76
72
  "eslint": "^8.17.0",
77
- "global-store": "1.0.0-beta.21",
78
73
  "jest": "^28.1.0",
79
74
  "npm-run-all": "^4.1.5",
80
75
  "param-case": "^3.0.4",
81
76
  "pascal-case": "^3.1.2",
77
+ "ramda": "^0.28.0",
82
78
  "rimraf": "^3.0.2",
83
79
  "size-limit": "^7.0.8",
84
80
  "ts-jest": "^28.0.4",
85
81
  "ts-loader": "^9.3.0",
82
+ "tslib": "^2.4.0",
86
83
  "typescript": "^4.7.3",
87
84
  "webpack": "^5.73.0",
88
85
  "webpack-bundle-analyzer": "^4.5.0",
89
86
  "webpack-cli": "^4.9.2"
90
87
  },
91
- "peerDependencies": {
92
- "global-store": "*"
93
- },
94
- "optionalDependencies": {
95
- "ramda": "^0.28.0"
96
- },
97
88
  "size-limit": [
98
89
  {
99
90
  "path": "./cjs/index.js",
package/ts/console.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { required } from 'type-plus'
2
+ import { logLevels } from './logLevels.js'
3
+ import { isConsoleDebugAvailable, polyfill } from './platform.js'
4
+ import { plainLogFormatter } from './formatter.js'
5
+ import type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'
6
+
7
+ export function toConsoleMethod(level: number) {
8
+ switch (true) {
9
+ // edge case in case none is somehow written
10
+ case (level <= 0): return 'debug'
11
+ case (level <= logLevels.error): return 'error'
12
+ case (level <= logLevels.warn): return 'warn'
13
+ case (level <= logLevels.info): return 'info'
14
+ default: return 'debug'
15
+ }
16
+ }
17
+
18
+ // istanbul ignore next
19
+ /* eslint-disable no-console */
20
+ function buildPolyfillConsole() {
21
+ // old phantomjs does not have bind function
22
+ const hasBind = !!console.log.bind as boolean
23
+ if (hasBind) {
24
+ return {
25
+ // Node@9.3 or below has `console.debug = undefined` or it doesn't log
26
+ // Should use `console.log()` in those case.
27
+ debug: (isConsoleDebugAvailable() ? console.debug : console.log).bind(console),
28
+ // the `typeof` guards against IE where `console.log.apply()`
29
+ // results in error `Object doesn't support property or method 'apply'`
30
+ info: (typeof console.info === 'function' ? console.info : console.log).bind(console),
31
+ warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),
32
+ error: (typeof console.error === 'function' ? console.error : console.log).bind(console)
33
+ }
34
+ }
35
+ else {
36
+ return {
37
+ debug: buildFn(isConsoleDebugAvailable() ? 'debug' : 'log'),
38
+ info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),
39
+ warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),
40
+ error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),
41
+ }
42
+ }
43
+ }
44
+
45
+ // istanbul ignore next
46
+ function buildFn(name: 'debug' | 'info' | 'warn' | 'error' | 'log') {
47
+ return function (...args: any[]) { console[name](...args) }
48
+ }
49
+
50
+
51
+ export type ConsoleLogFormatter = LogFormatter<any[]>
52
+ export type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }
53
+ export type ConsoleLogReporterOptions = LogReporterOptions<any[]>
54
+
55
+ export function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {
56
+ const { id, formatter, filter } = required({ id: 'console', formatter: plainLogFormatter }, options)
57
+ if (!polyfill.console) polyfill.console = buildPolyfillConsole()
58
+
59
+ return Object.freeze({
60
+ id,
61
+ isConsoleReporter: true,
62
+ get formatter() { return formatter },
63
+ get filter() { return filter },
64
+ console: polyfill.console,
65
+ write(entry: LogEntry) {
66
+ if (filter && !filter(entry)) return
67
+ const values = formatter(entry)
68
+ const method = toConsoleMethod(entry.level)
69
+ this.console[method](...values)
70
+ }
71
+ })
72
+ }
package/ts/errors.ts CHANGED
@@ -10,15 +10,3 @@ export class InvalidId extends StandardLogError {
10
10
  super(`logger id only supports alphanumeric, unicode characters, and [:_-.]. Received ${id}`, options)
11
11
  }
12
12
  }
13
-
14
- export class ProhibitedDuringProduction extends StandardLogError {
15
- constructor(public action: string, options?: IsoError.Options) {
16
- super(`Cannot perform ${action} during production`, options)
17
- }
18
- }
19
-
20
- export class InvalidEnvVar extends StandardLogError {
21
- constructor(public name: string, public value: string, public possibleValues: string[], options?: IsoError.Options) {
22
- super(`${name} contains invalid value '${value}'${` valid values: [${possibleValues.join()}]`}`, options)
23
- }
24
- }
@@ -1,4 +1,7 @@
1
1
  import ms from 'ms'
2
+ import { upperCase } from 'upper-case'
3
+ import { toLogLevelName } from './logLevels.js'
4
+ import type { LogEntry } from './types.js'
2
5
 
3
6
  export type TimestampFormat = 'none' | 'iso' | 'elapsed'
4
7
 
@@ -9,7 +12,7 @@ export function createTimestampFormatter(format: TimestampFormat) {
9
12
  case 'iso':
10
13
  return (timestamp: Date) => timestamp.toISOString()
11
14
  case 'elapsed': {
12
- let lastTick: number | undefined = undefined
15
+ let lastTick: number
13
16
  return (timestamp: Date) => {
14
17
  const newTick = timestamp.getTime()
15
18
  const result = ms(lastTick === undefined ? 0 : newTick - lastTick)
@@ -19,3 +22,11 @@ export function createTimestampFormatter(format: TimestampFormat) {
19
22
  }
20
23
  }
21
24
  }
25
+
26
+ export function formatLogLevel(level: number) {
27
+ return `(${upperCase(toLogLevelName(level))})`
28
+ }
29
+
30
+ export function plainLogFormatter({ id, level, args, timestamp }: LogEntry) {
31
+ return [timestamp.toISOString(), id, formatLogLevel(level), ...args]
32
+ }
package/ts/index.ts CHANGED
@@ -1,16 +1,7 @@
1
- export * from './captureLogs.js'
2
- export * from './config.js'
3
- export * from './configForTest.js'
4
- export * from './console/index.js'
5
- export * from './customLogLevel.js'
1
+ export * from './console.js'
6
2
  export * from './errors.js'
7
- export * from './formatter/index.js'
8
- export * from './getLogger.js'
9
- export * from './logLevel.js'
10
- export * from './logLevelFn.js'
11
- export * from './logReporter.js'
12
- export * from './memory/index.js'
13
- export * from './shouldLog.js'
14
- export * from './suppressLogs.js'
3
+ export * from './formatter.js'
4
+ export * from './logLevels.js'
5
+ export * from './memory.js'
6
+ export * from './standardLog.js'
15
7
  export * from './types.js'
16
- export * from './utils.js'
@@ -1,4 +1,3 @@
1
-
2
1
  export const logLevels = {
3
2
  /**
4
3
  * none: 0
@@ -52,6 +51,24 @@ export const logLevels = {
52
51
  }
53
52
 
54
53
  /**
55
- * @deprecated logLevel is renamed to logLevels
54
+ * Convert default log level value to log level name.
55
+ */
56
+ export function toLogLevelName(level: number) {
57
+ if (level <= 100) return 'emergency'
58
+ if (level <= 200) return 'alert'
59
+ if (level <= 300) return 'critical'
60
+ if (level <= 400) return 'error'
61
+ if (level <= 500) return 'warn'
62
+ if (level <= 600) return 'notice'
63
+ if (level <= 700) return 'info'
64
+ if (level <= 800) return 'debug'
65
+ if (level <= 900) return 'trace'
66
+ return 'planck'
67
+ }
68
+
69
+ /**
70
+ * Convert default log level name to log level value.
56
71
  */
57
- export const logLevel = logLevels
72
+ export function toLogLevel(name: string) {
73
+ return (logLevels as any)[name.toLocaleLowerCase()]
74
+ }
package/ts/logStore.ts ADDED
@@ -0,0 +1,52 @@
1
+
2
+ import { mapKey, reduceByKey, reduceKey } from 'type-plus'
3
+ import { createConsoleLogReporter } from './console.js'
4
+ import { logLevels, toLogLevel, toLogLevelName } from './logLevels.js'
5
+ import type { Logger, LogLevel, LogReporter, StandardLogOptions } from './types.js'
6
+
7
+ export function createLogStore(options: StandardLogOptions): LogStore {
8
+ return {
9
+ loggers: {},
10
+ reporters: options.reporters || [createConsoleLogReporter()],
11
+ logLevel: options.logLevel,
12
+ logLevelStore: logLevelStore(options)
13
+ }
14
+ }
15
+
16
+ export interface LogStore {
17
+ loggers: Record<string, Logger>,
18
+ reporters: LogReporter[],
19
+ logLevel: LogLevel,
20
+ logLevelStore: ReturnType<typeof logLevelStore>
21
+ }
22
+
23
+ export interface LogLevelStoreOptions {
24
+ customLevels?: Record<string, number>
25
+ }
26
+
27
+ export function logLevelStore(options: LogLevelStoreOptions) {
28
+ const customLevels = options.customLevels || {}
29
+
30
+ const store = {
31
+ customLevels,
32
+ customLevelsReverse: reduceByKey(customLevels, (p, k) => {
33
+ p[customLevels[k]] = k
34
+ return p
35
+ }, {} as Record<number, string>)
36
+ }
37
+ return {
38
+ getName(level: number) {
39
+ return store.customLevelsReverse[level] ?? toLogLevelName(level)
40
+ },
41
+ getLevel(name: string) {
42
+ return store.customLevels[name] ?? toLogLevel(name)
43
+ },
44
+ getAllLevels() {
45
+ return reduceKey(logLevels, (result, name) => {
46
+ if (name !== 'none' && name !== 'all') result.push({ name, level: logLevels[name] })
47
+
48
+ return result
49
+ }, mapKey(store.customLevels, name => ({ name, level: store.customLevels[name] })))
50
+ }
51
+ }
52
+ }
package/ts/logger.ts ADDED
@@ -0,0 +1,85 @@
1
+ import type { StackTraceMeta } from '@just-func/types'
2
+ import { RequiredPick } from 'type-plus'
3
+ import { InvalidId } from './errors.js'
4
+ import { logLevels } from './logLevels.js'
5
+ import { LogStore } from './logStore.js'
6
+ import type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'
7
+ import { LogLevel } from './types.js'
8
+
9
+ export function createLogger<T extends string = LogMethodNames>(
10
+ [store, id, { level, writeTo = () => true }]: [LogStore, string, RequiredPick<LoggerOptions, 'level'>],
11
+ meta?: StackTraceMeta
12
+ ): Logger {
13
+ validateId(id, meta)
14
+ const [filter, reporters]: [(reporterId: string) => boolean, LogReporter[]] = typeof writeTo === 'string'
15
+ ? [id => id === writeTo, store.reporters]
16
+ : writeTo instanceof RegExp
17
+ ? [id => writeTo.test(id), store.reporters]
18
+ : typeof writeTo === 'function'
19
+ ? [writeTo, store.reporters]
20
+ : [() => true, [writeTo]]
21
+
22
+ function write(entry: LogEntry) {
23
+ writeToReporters(reporters, entry, filter)
24
+ }
25
+
26
+ const logger = {
27
+ level,
28
+ write
29
+ } as any
30
+
31
+ Object.defineProperties(logger, {
32
+ id: { value: id, writable: false },
33
+ count: {
34
+ writable: false,
35
+ value: ((counter) => (...args: any[]) => {
36
+ const level = logLevels.debug
37
+ if (shouldLog(store, level, logger.level))
38
+ write({
39
+ id,
40
+ level,
41
+ args: [++counter, ...args],
42
+ timestamp: new Date()
43
+ })
44
+ })(0)
45
+ },
46
+ on: {
47
+ writable: false,
48
+ value: (level: number | T, logFn: LogFunction) => {
49
+ const logLevel = typeof level === 'string' ? store.logLevelStore.getLevel(level)! : level
50
+ if (shouldLog(store, logLevel, logger.level)) {
51
+ const methodName = store.logLevelStore.getName(logLevel)
52
+ const bindedMethod = logger[methodName].bind(logger)
53
+ const result = logFn(bindedMethod)
54
+ if (result) bindedMethod(result)
55
+ }
56
+ }
57
+ }
58
+ })
59
+ store.logLevelStore.getAllLevels().forEach(function addMethod({ name, level }) {
60
+ Object.defineProperty(logger, name, {
61
+ writable: false,
62
+ value: (...args: any[]) => {
63
+ if (shouldLog(store, level, logger.level)) write({ id, level, args, timestamp: new Date() })
64
+ }
65
+ })
66
+ })
67
+ return logger
68
+ }
69
+
70
+ function validateId(id: string, meta?: StackTraceMeta) {
71
+ if (/[`~!#$%^&*()=+[\]{},|<>?]/.test(id)) throw new InvalidId(id, meta)
72
+ }
73
+
74
+ function writeToReporters(reporters: LogReporter[], logEntry: LogEntry, filter: (reporterId: string) => boolean) {
75
+ reporters.filter(r => filter(r.id)).forEach(r => r.write(logEntry!))
76
+ }
77
+
78
+ /**
79
+ * Determines should you log.
80
+ * @param loggerLevel Log level of the logger.
81
+ * It can be undefined which the global log level will be used.
82
+ */
83
+ function shouldLog(store: LogStore, targetLevel: LogLevel, loggerLevel: LogLevel | undefined) {
84
+ return targetLevel <= (loggerLevel !== undefined ? loggerLevel : store.logLevel)
85
+ }
package/ts/memory.ts ADDED
@@ -0,0 +1,47 @@
1
+ import { required } from 'type-plus'
2
+ import { toInspectLogEntry } from './platform.js'
3
+ import { formatLogLevel } from './formatter.js'
4
+ import type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'
5
+
6
+ export type MemoryLogReporter = LogReporter<LogEntry> & {
7
+ logs: LogEntry[],
8
+ /**
9
+ * Gets a simple log message for testing.
10
+ * The message only contains arguments for each log entry.
11
+ */
12
+ getLogMessage(): string,
13
+ getLogMessageWithLevel(): string
14
+ }
15
+
16
+ export type MemoryLogFormatter = LogFormatter<LogEntry>
17
+
18
+ export function toMessageWithLevel(logs: LogEntry[]) {
19
+ return logs.map(toInspectLogEntry)
20
+ .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)
21
+ .join('\n')
22
+ // if it has more than this log,
23
+ // we assume it is running under tests,
24
+ // and remove this log to simplify testing.
25
+ .replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, '')
26
+ }
27
+
28
+ export function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {
29
+ const { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)
30
+ const logs: LogEntry[] = []
31
+ return Object.freeze({
32
+ id,
33
+ get formatter() { return formatter },
34
+ get filter() { return filter },
35
+ logs,
36
+ write(entry: LogEntry) {
37
+ if (filter && !filter(entry)) return
38
+ logs.push(formatter(entry))
39
+ },
40
+ getLogMessage() {
41
+ return logs.map(toInspectLogEntry)
42
+ .map(log => log.args.join(' '))
43
+ .join('\n')
44
+ },
45
+ getLogMessageWithLevel() { return toMessageWithLevel(logs) }
46
+ })
47
+ }
@@ -0,0 +1,8 @@
1
+ import type { ConsoleLike, LogEntry } from './types.js'
2
+
3
+ export const toInspectLogEntry = (e: LogEntry) => e
4
+ export function isConsoleDebugAvailable() {
5
+ return true
6
+ }
7
+
8
+ export const polyfill: { console?: ConsoleLike } = {}
package/ts/platform.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { inspect } from 'util'
2
+ import type { ConsoleLike, LogEntry } from './types.js'
3
+
4
+ export function semverGt(versionString: string, version: [number, number, number]) {
5
+ const actual = versionString.split('.').reverse().reduce((p, v, i) => {
6
+ p += Number.parseInt(v, 10) * Math.pow(100, i)
7
+ return p
8
+ }, 0)
9
+
10
+ return actual > (version[0] * 10000 + version[1] * 100 + version[2])
11
+ }
12
+
13
+ // istanbul ignore next
14
+ export function isConsoleDebugAvailable() {
15
+ // without this, systemJs will complain `process is not defined`
16
+ if (!global.process) return true
17
+ const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version
18
+ return semverGt(versionString, [9, 3, 0])
19
+ }
20
+
21
+ export const toInspectLogEntry = (e: LogEntry) => (
22
+ e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),
23
+ e)
24
+
25
+ export const polyfill: { console?: ConsoleLike } = {}
@@ -0,0 +1,54 @@
1
+ import { StackTraceMeta } from '@just-func/types'
2
+ import { required } from 'type-plus'
3
+ import { createLogger } from './logger.js'
4
+ import { logLevels } from './logLevels.js'
5
+ import { createLogStore } from './logStore.js'
6
+ import { createMemoryLogReporter } from './memory.js'
7
+ import type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js'
8
+
9
+ export interface StandardLog<N extends string = LogMethodNames> {
10
+ readonly logLevel: number,
11
+ toLogLevelName(level: number): string,
12
+ toLogLevel(name: N): number,
13
+ getLogger(params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N>
14
+ }
15
+
16
+ export function createStandardLog<N extends string = LogMethodNames>(
17
+ options?: Partial<StandardLogOptions<N>>, _meta?: StackTraceMeta
18
+ ): Readonly<StandardLog<N>> {
19
+ const store = createLogStore(required({ logLevel: logLevels.info }, options))
20
+
21
+ return Object.freeze({
22
+ get logLevel() { return store.logLevel },
23
+
24
+ toLogLevelName(level: number) {
25
+ return store.logLevelStore.getName(level)
26
+ },
27
+ toLogLevel(name: string) {
28
+ return store.logLevelStore.getLevel(name)
29
+ },
30
+ getLogger([id, options]: [id: string, options?: LoggerOptions], meta?: StackTraceMeta): Logger<N> {
31
+ if (store.loggers[id]) return store.loggers[id] as any
32
+ const opt = required({ level: store.logLevel }, options)
33
+ return store.loggers[id] = createLogger([store, id, opt], { ssf: this.getLogger, ...meta }) as any
34
+ }
35
+ })
36
+ }
37
+
38
+ export function createStandardLogForTest(logLevel: LogLevel = logLevels.debug) {
39
+ const reporter = createMemoryLogReporter()
40
+ const standardLog = createStandardLog({ reporters: [reporter], logLevel })
41
+ return { ...standardLog, reporter }
42
+ }
43
+
44
+ /**
45
+ * Suppress logging within the code block.
46
+ */
47
+ export function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R
48
+ export function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {
49
+ const origLevels = logs.map(l => l.level)
50
+ logs.forEach(l => l.level = logLevels.none)
51
+ const result = block()
52
+ logs.forEach((l, i) => l.level = origLevels[i])
53
+ return result
54
+ }