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
package/esm/testUtil.js CHANGED
@@ -1,21 +1,17 @@
1
1
  import R from 'ramda';
2
- import { writeToReporters } from './writeToReporters.js';
2
+ import { plainLogFormatter } from './formatter.js';
3
+ import { toInspectLogEntry } from './platform.js';
3
4
  export function rangeEntries(start, end, expected) {
4
5
  return R.range(start, end).map(value => ([value, expected]));
5
6
  }
6
- export function captureWrittenLog() {
7
- const logs = [];
8
- const orig = writeToReporters.fn;
9
- writeToReporters.fn = l => logs.push(l);
10
- return {
11
- logs,
12
- reset() {
13
- writeToReporters.fn = orig;
14
- }
15
- };
16
- }
17
7
  export function assertSSF(err, filename) {
18
8
  const firstStackTrace = err.stack?.split('\n')[1];
19
9
  expect(firstStackTrace).toMatch(filename);
20
10
  }
11
+ export function logEntriesToString(logs) {
12
+ return logs.map(toInspectLogEntry).map(plainLogFormatter).join('\n');
13
+ }
14
+ export function wrapTest(fn) {
15
+ return Object.assign(fn(test), { only: fn(test.only), skip: fn(test.skip) });
16
+ }
21
17
  //# sourceMappingURL=testUtil.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testUtil.js","sourceRoot":"","sources":["../ts/testUtil.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,OAAO,CAAA;AAErB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,GAAW,EAAE,QAAa;IACpE,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;AAC9D,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,IAAI,GAAe,EAAE,CAAA;IAC3B,MAAM,IAAI,GAAG,gBAAgB,CAAC,EAAE,CAAA;IAChC,gBAAgB,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACvC,OAAO;QACL,IAAI;QACJ,KAAK;YACH,gBAAgB,CAAC,EAAE,GAAG,IAAI,CAAA;QAC5B,CAAC;KACF,CAAA;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAU,EAAE,QAAgB;IACpD,MAAM,eAAe,GAAG,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AAC3C,CAAC","sourcesContent":["import R from 'ramda'\nimport { LogEntry } from './types.js'\nimport { writeToReporters } from './writeToReporters.js'\n\nexport function rangeEntries(start: number, end: number, expected: any) {\n return R.range(start, end).map(value => ([value, expected]))\n}\n\nexport function captureWrittenLog() {\n const logs: LogEntry[] = []\n const orig = writeToReporters.fn\n writeToReporters.fn = l => logs.push(l)\n return {\n logs,\n reset() {\n writeToReporters.fn = orig\n }\n }\n}\n\nexport function assertSSF(err: Error, filename: string) {\n const firstStackTrace = err.stack?.split('\\n')[1]\n expect(firstStackTrace).toMatch(filename)\n}\n"]}
1
+ {"version":3,"file":"testUtil.js","sourceRoot":"","sources":["../ts/testUtil.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,OAAO,CAAA;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGjD,MAAM,UAAU,YAAY,CAAC,KAAa,EAAE,GAAW,EAAE,QAAa;IACpE,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;AAC9D,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAU,EAAE,QAAgB;IACpD,MAAM,eAAe,GAAG,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAgB;IACjD,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACtE,CAAC;AAED,MAAM,UAAU,QAAQ,CAAI,EAAwB;IAClD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import R from 'ramda'\nimport { plainLogFormatter } from './formatter.js'\nimport { toInspectLogEntry } from './platform.js'\nimport type { LogEntry } from './types.js'\n\nexport function rangeEntries(start: number, end: number, expected: any) {\n return R.range(start, end).map(value => ([value, expected]))\n}\n\nexport function assertSSF(err: Error, filename: string) {\n const firstStackTrace = err.stack?.split('\\n')[1]\n expect(firstStackTrace).toMatch(filename)\n}\n\nexport function logEntriesToString(logs: LogEntry[]) {\n return logs.map(toInspectLogEntry).map(plainLogFormatter).join('\\n')\n}\n\nexport function wrapTest<F>(fn: (test: jest.It) => F) {\n return Object.assign(fn(test), { only: fn(test.only), skip: fn(test.skip) })\n}\n"]}
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,CAAC,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAA;CAC1B,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.1.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,70 @@
1
+ import { required } from 'type-plus'
2
+ import { plainLogFormatter } from './formatter.js'
3
+ import { logLevels } from './logLevels.js'
4
+ import { polyfill } from './platform.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
+ // the `typeof` guards against IE where `console.log.apply()`
26
+ // results in error `Object doesn't support property or method 'apply'`
27
+ debug: (typeof console.info === 'function' ? console.debug : console.log).bind(console),
28
+ info: (typeof console.info === 'function' ? console.info : console.log).bind(console),
29
+ warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),
30
+ error: (typeof console.error === 'function' ? console.error : console.log).bind(console)
31
+ }
32
+ }
33
+ else {
34
+ return {
35
+ debug: buildFn(typeof console.debug === 'function' ? 'debug' : 'log'),
36
+ info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),
37
+ warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),
38
+ error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),
39
+ }
40
+ }
41
+ }
42
+
43
+ // istanbul ignore next
44
+ function buildFn(name: 'debug' | 'info' | 'warn' | 'error' | 'log') {
45
+ return function (...args: any[]) { console[name](...args) }
46
+ }
47
+
48
+
49
+ export type ConsoleLogFormatter = LogFormatter<any[]>
50
+ export type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }
51
+ export type ConsoleLogReporterOptions = LogReporterOptions<any[]>
52
+
53
+ export function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {
54
+ const { id, formatter, filter } = required({ id: 'console', formatter: plainLogFormatter }, options)
55
+ if (!polyfill.console) polyfill.console = buildPolyfillConsole()
56
+
57
+ return Object.freeze({
58
+ id,
59
+ isConsoleReporter: true,
60
+ get formatter() { return formatter },
61
+ get filter() { return filter },
62
+ console: polyfill.console,
63
+ write(entry: LogEntry) {
64
+ if (filter && !filter(entry)) return
65
+ const values = formatter(entry)
66
+ const method = toConsoleMethod(entry.level)
67
+ this.console[method](...values)
68
+ }
69
+ })
70
+ }
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/global.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { StackTraceMeta } from '@just-func/types'
2
+ import { record } from 'type-plus'
3
+ import { LogStore } from './logStore.js'
4
+ import { createStandardLogClosure, StandardLogInstance } from './standardLog.js'
5
+ import { LoggerOptions, LogMethodNames, StandardLogOptions } from './types.js'
6
+
7
+ export function getLogger<N extends string = LogMethodNames>(
8
+ params: [id: string, options?: LoggerOptions], meta?: StackTraceMeta) {
9
+ return getGlobalSL<N>().getLogger(params, meta)
10
+ }
11
+
12
+ export const ctx: { gsl?: { store: LogStore, standardLog: StandardLogInstance<any> } } = record()
13
+
14
+ function getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {
15
+ if (!ctx.gsl) configGlobal({})
16
+
17
+ return ctx.gsl!.standardLog
18
+ }
19
+
20
+ export function configGlobal<N extends string = LogMethodNames>(options: Omit<StandardLogOptions, 'customLevels'>) {
21
+ if (ctx.gsl) {
22
+ if (options.logLevel) {
23
+ ctx.gsl.store.logLevel = options.logLevel
24
+ }
25
+ if (options.reporters) {
26
+ const reporters = ctx.gsl.store.reporters
27
+ while (reporters.length > 0) reporters.pop()
28
+ reporters.push(...options.reporters)
29
+ }
30
+ }
31
+ else {
32
+ ctx.gsl = createStandardLogClosure<N>(options)
33
+ }
34
+ }
package/ts/index.ts CHANGED
@@ -1,16 +1,11 @@
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 { configGlobal, getLogger } from './global.js'
5
+ export * from './logLevels.js'
6
+ export * from './memory.js'
7
+ export {
8
+ createStandardLog, createStandardLogForTest, StandardLog, StandardLogInstance
9
+ } from './standardLog.js'
15
10
  export * from './types.js'
16
- export * from './utils.js'
11
+
@@ -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: Required<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 { InvalidId } from './errors.js'
3
+ import { logLevels } from './logLevels.js'
4
+ import { LogStore } from './logStore.js'
5
+ import type { LogEntry, LogFunction, Logger, LoggerOptions, LogMethodNames, LogReporter } from './types.js'
6
+ import { LogLevel } from './types.js'
7
+
8
+ export function createLogger<T extends string = LogMethodNames>(
9
+ [store, id, options]: [LogStore, string, LoggerOptions | undefined],
10
+ meta?: StackTraceMeta
11
+ ): Logger {
12
+ validateId(id, meta)
13
+ const writeTo = options?.writeTo ?? (() => true)
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: options?.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
+ }