standard-log 7.1.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (551) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +57 -133
  3. package/{libm/console/createConsoleLogReporter.d.ts → cjs/console.d.ts} +5 -5
  4. package/cjs/console.d.ts.map +1 -0
  5. package/cjs/console.js +76 -0
  6. package/cjs/console.js.map +1 -0
  7. package/cjs/console.spec.d.ts +2 -0
  8. package/cjs/console.spec.d.ts.map +1 -0
  9. package/cjs/console.spec.js +177 -0
  10. package/cjs/console.spec.js.map +1 -0
  11. package/cjs/errors.d.ts +9 -0
  12. package/cjs/errors.d.ts.map +1 -0
  13. package/cjs/errors.js +43 -0
  14. package/cjs/errors.js.map +1 -0
  15. package/cjs/formatter.d.ts +6 -0
  16. package/cjs/formatter.d.ts.map +1 -0
  17. package/cjs/formatter.js +46 -0
  18. package/cjs/formatter.js.map +1 -0
  19. package/cjs/formatter.spec.d.ts +2 -0
  20. package/cjs/formatter.spec.d.ts.map +1 -0
  21. package/cjs/formatter.spec.js +32 -0
  22. package/cjs/formatter.spec.js.map +1 -0
  23. package/cjs/index.d.ts +8 -0
  24. package/cjs/index.d.ts.map +1 -0
  25. package/cjs/index.js +24 -0
  26. package/cjs/index.js.map +1 -0
  27. package/cjs/logLevels.d.ts +60 -0
  28. package/cjs/logLevels.d.ts.map +1 -0
  29. package/cjs/logLevels.js +87 -0
  30. package/cjs/logLevels.js.map +1 -0
  31. package/cjs/logStore.d.ts +20 -0
  32. package/cjs/logStore.d.ts.map +1 -0
  33. package/cjs/logStore.js +44 -0
  34. package/cjs/logStore.js.map +1 -0
  35. package/cjs/logStore.spec.d.ts +2 -0
  36. package/cjs/logStore.spec.d.ts.map +1 -0
  37. package/cjs/logStore.spec.js +93 -0
  38. package/cjs/logStore.spec.js.map +1 -0
  39. package/cjs/logger.d.ts +6 -0
  40. package/cjs/logger.d.ts.map +1 -0
  41. package/cjs/logger.js +97 -0
  42. package/cjs/logger.js.map +1 -0
  43. package/{lib/memory/MemoryLogReporter.d.ts → cjs/memory.d.ts} +2 -2
  44. package/cjs/memory.d.ts.map +1 -0
  45. package/cjs/memory.js +39 -0
  46. package/cjs/memory.js.map +1 -0
  47. package/cjs/memory.spec.d.ts +2 -0
  48. package/cjs/memory.spec.d.ts.map +1 -0
  49. package/cjs/memory.spec.js +115 -0
  50. package/cjs/memory.spec.js.map +1 -0
  51. package/cjs/package.json +1 -0
  52. package/cjs/platform.browser.d.ts +7 -0
  53. package/cjs/platform.browser.d.ts.map +1 -0
  54. package/cjs/platform.browser.js +11 -0
  55. package/cjs/platform.browser.js.map +1 -0
  56. package/cjs/platform.d.ts +8 -0
  57. package/cjs/platform.d.ts.map +1 -0
  58. package/cjs/platform.js +26 -0
  59. package/cjs/platform.js.map +1 -0
  60. package/cjs/platform.spec.d.ts +2 -0
  61. package/cjs/platform.spec.d.ts.map +1 -0
  62. package/cjs/platform.spec.js +22 -0
  63. package/cjs/platform.spec.js.map +1 -0
  64. package/cjs/standardLog.d.ts +21 -0
  65. package/cjs/standardLog.d.ts.map +1 -0
  66. package/cjs/standardLog.js +59 -0
  67. package/cjs/standardLog.js.map +1 -0
  68. package/cjs/standardLog.spec.d.ts +2 -0
  69. package/cjs/standardLog.spec.d.ts.map +1 -0
  70. package/cjs/standardLog.spec.js +536 -0
  71. package/cjs/standardLog.spec.js.map +1 -0
  72. package/cjs/testUtil.d.ts +10 -0
  73. package/cjs/testUtil.d.ts.map +1 -0
  74. package/cjs/testUtil.js +28 -0
  75. package/cjs/testUtil.js.map +1 -0
  76. package/{lib → cjs}/types.d.ts +33 -24
  77. package/cjs/types.d.ts.map +1 -0
  78. package/{lib/console → cjs}/types.js +0 -0
  79. package/cjs/types.js.map +1 -0
  80. package/cjs/types.spec.d.ts +2 -0
  81. package/cjs/types.spec.d.ts.map +1 -0
  82. package/cjs/types.spec.js +7 -0
  83. package/cjs/types.spec.js.map +1 -0
  84. package/dist/standard-log.es5.js +1971 -0
  85. package/dist/standard-log.es5.js.gz +0 -0
  86. package/dist/standard-log.es5.js.map +1 -0
  87. package/dist/standard-log.es5.js.map.gz +0 -0
  88. package/dist/standard-log.esm.js +1887 -0
  89. package/dist/standard-log.esm.js.gz +0 -0
  90. package/dist/standard-log.esm.js.map +1 -0
  91. package/dist/standard-log.esm.js.map.gz +0 -0
  92. package/{lib/console/createConsoleLogReporter.d.ts → esm/console.d.ts} +5 -5
  93. package/esm/console.d.ts.map +1 -0
  94. package/{libm/console/polyfilledConsole.js → esm/console.js} +36 -4
  95. package/esm/console.js.map +1 -0
  96. package/esm/console.spec.d.ts +2 -0
  97. package/esm/console.spec.d.ts.map +1 -0
  98. package/esm/console.spec.js +151 -0
  99. package/esm/console.spec.js.map +1 -0
  100. package/esm/errors.d.ts +9 -0
  101. package/esm/errors.d.ts.map +1 -0
  102. package/esm/errors.js +18 -0
  103. package/esm/errors.js.map +1 -0
  104. package/esm/formatter.d.ts +6 -0
  105. package/esm/formatter.d.ts.map +1 -0
  106. package/{libm/formatter/createTimestampFormatter.js → esm/formatter.js} +10 -2
  107. package/esm/formatter.js.map +1 -0
  108. package/esm/formatter.spec.d.ts +2 -0
  109. package/esm/formatter.spec.d.ts.map +1 -0
  110. package/esm/formatter.spec.js +30 -0
  111. package/esm/formatter.spec.js.map +1 -0
  112. package/esm/index.d.ts +8 -0
  113. package/esm/index.d.ts.map +1 -0
  114. package/esm/index.js +8 -0
  115. package/esm/index.js.map +1 -0
  116. package/esm/logLevels.d.ts +60 -0
  117. package/esm/logLevels.d.ts.map +1 -0
  118. package/{libm/logLevel.js → esm/logLevels.js} +29 -3
  119. package/esm/logLevels.js.map +1 -0
  120. package/esm/logStore.d.ts +20 -0
  121. package/esm/logStore.d.ts.map +1 -0
  122. package/esm/logStore.js +37 -0
  123. package/esm/logStore.js.map +1 -0
  124. package/esm/logStore.spec.d.ts +2 -0
  125. package/esm/logStore.spec.d.ts.map +1 -0
  126. package/esm/logStore.spec.js +93 -0
  127. package/esm/logStore.spec.js.map +1 -0
  128. package/esm/logger.d.ts +6 -0
  129. package/esm/logger.d.ts.map +1 -0
  130. package/esm/logger.js +74 -0
  131. package/esm/logger.js.map +1 -0
  132. package/{libm/memory/MemoryLogReporter.d.ts → esm/memory.d.ts} +2 -2
  133. package/esm/memory.d.ts.map +1 -0
  134. package/esm/memory.js +34 -0
  135. package/esm/memory.js.map +1 -0
  136. package/esm/memory.spec.d.ts +2 -0
  137. package/esm/memory.spec.d.ts.map +1 -0
  138. package/esm/memory.spec.js +110 -0
  139. package/esm/memory.spec.js.map +1 -0
  140. package/esm/platform.browser.d.ts +7 -0
  141. package/esm/platform.browser.d.ts.map +1 -0
  142. package/esm/platform.browser.js +6 -0
  143. package/esm/platform.browser.js.map +1 -0
  144. package/esm/platform.d.ts +8 -0
  145. package/esm/platform.d.ts.map +1 -0
  146. package/esm/platform.js +20 -0
  147. package/esm/platform.js.map +1 -0
  148. package/esm/platform.spec.d.ts +2 -0
  149. package/esm/platform.spec.d.ts.map +1 -0
  150. package/esm/platform.spec.js +20 -0
  151. package/esm/platform.spec.js.map +1 -0
  152. package/esm/standardLog.d.ts +21 -0
  153. package/esm/standardLog.d.ts.map +1 -0
  154. package/esm/standardLog.js +36 -0
  155. package/esm/standardLog.js.map +1 -0
  156. package/esm/standardLog.spec.d.ts +2 -0
  157. package/esm/standardLog.spec.d.ts.map +1 -0
  158. package/esm/standardLog.spec.js +434 -0
  159. package/esm/standardLog.spec.js.map +1 -0
  160. package/esm/testUtil.d.ts +10 -0
  161. package/esm/testUtil.d.ts.map +1 -0
  162. package/esm/testUtil.js +17 -0
  163. package/esm/testUtil.js.map +1 -0
  164. package/{libm → esm}/types.d.ts +33 -24
  165. package/esm/types.d.ts.map +1 -0
  166. package/{libm/console → esm}/types.js +0 -0
  167. package/esm/types.js.map +1 -0
  168. package/esm/types.spec.d.ts +2 -0
  169. package/esm/types.spec.d.ts.map +1 -0
  170. package/esm/types.spec.js +5 -0
  171. package/esm/types.spec.js.map +1 -0
  172. package/package.json +72 -31
  173. package/ts/console.ts +72 -0
  174. package/ts/errors.ts +12 -0
  175. package/{src/formatter/createTimestampFormatter.ts → ts/formatter.ts} +13 -2
  176. package/ts/index.ts +7 -0
  177. package/{src/logLevel.ts → ts/logLevels.ts} +20 -3
  178. package/ts/logStore.ts +52 -0
  179. package/ts/logger.ts +85 -0
  180. package/ts/memory.ts +47 -0
  181. package/ts/platform.browser.ts +8 -0
  182. package/ts/platform.ts +25 -0
  183. package/ts/standardLog.ts +54 -0
  184. package/{src → ts}/types.ts +39 -30
  185. package/dist/standard-log.js +0 -5472
  186. package/dist/standard-log.js.gz +0 -0
  187. package/dist/standard-log.js.map +0 -1
  188. package/dist/standard-log.js.map.gz +0 -0
  189. package/lib/LogEntry.d.ts +0 -7
  190. package/lib/LogEntry.d.ts.map +0 -1
  191. package/lib/LogEntry.js +0 -3
  192. package/lib/LogEntry.js.map +0 -1
  193. package/lib/captureLogs.d.ts +0 -4
  194. package/lib/captureLogs.d.ts.map +0 -1
  195. package/lib/captureLogs.js +0 -33
  196. package/lib/captureLogs.js.map +0 -1
  197. package/lib/config.d.ts +0 -12
  198. package/lib/config.d.ts.map +0 -1
  199. package/lib/config.js +0 -49
  200. package/lib/config.js.map +0 -1
  201. package/lib/configForTest.d.ts +0 -5
  202. package/lib/configForTest.d.ts.map +0 -1
  203. package/lib/configForTest.js +0 -18
  204. package/lib/configForTest.js.map +0 -1
  205. package/lib/console/createConsoleLogReporter.d.ts.map +0 -1
  206. package/lib/console/createConsoleLogReporter.js +0 -42
  207. package/lib/console/createConsoleLogReporter.js.map +0 -1
  208. package/lib/console/index.d.ts +0 -4
  209. package/lib/console/index.d.ts.map +0 -1
  210. package/lib/console/index.js +0 -7
  211. package/lib/console/index.js.map +0 -1
  212. package/lib/console/isConsoleDebugAvailable.d.ts +0 -2
  213. package/lib/console/isConsoleDebugAvailable.d.ts.map +0 -1
  214. package/lib/console/isConsoleDebugAvailable.js +0 -18
  215. package/lib/console/isConsoleDebugAvailable.js.map +0 -1
  216. package/lib/console/polyfilledConsole.d.ts +0 -7
  217. package/lib/console/polyfilledConsole.d.ts.map +0 -1
  218. package/lib/console/polyfilledConsole.js +0 -41
  219. package/lib/console/polyfilledConsole.js.map +0 -1
  220. package/lib/console/semverGt.d.ts +0 -2
  221. package/lib/console/semverGt.d.ts.map +0 -1
  222. package/lib/console/semverGt.js +0 -13
  223. package/lib/console/semverGt.js.map +0 -1
  224. package/lib/console/toConsoleMethod.d.ts +0 -2
  225. package/lib/console/toConsoleMethod.d.ts.map +0 -1
  226. package/lib/console/toConsoleMethod.js +0 -22
  227. package/lib/console/toConsoleMethod.js.map +0 -1
  228. package/lib/console/types.d.ts +0 -3
  229. package/lib/console/types.d.ts.map +0 -1
  230. package/lib/console/types.js.map +0 -1
  231. package/lib/customLogLevel.d.ts +0 -11
  232. package/lib/customLogLevel.d.ts.map +0 -1
  233. package/lib/customLogLevel.js +0 -38
  234. package/lib/customLogLevel.js.map +0 -1
  235. package/lib/errors.d.ts +0 -19
  236. package/lib/errors.d.ts.map +0 -1
  237. package/lib/errors.js +0 -46
  238. package/lib/errors.js.map +0 -1
  239. package/lib/formatter/createTimestampFormatter.d.ts +0 -3
  240. package/lib/formatter/createTimestampFormatter.d.ts.map +0 -1
  241. package/lib/formatter/createTimestampFormatter.js +0 -24
  242. package/lib/formatter/createTimestampFormatter.js.map +0 -1
  243. package/lib/formatter/formatLogLevel.d.ts +0 -2
  244. package/lib/formatter/formatLogLevel.d.ts.map +0 -1
  245. package/lib/formatter/formatLogLevel.js +0 -10
  246. package/lib/formatter/formatLogLevel.js.map +0 -1
  247. package/lib/formatter/index.d.ts +0 -4
  248. package/lib/formatter/index.d.ts.map +0 -1
  249. package/lib/formatter/index.js +0 -7
  250. package/lib/formatter/index.js.map +0 -1
  251. package/lib/formatter/plainLogFormatter.d.ts +0 -3
  252. package/lib/formatter/plainLogFormatter.d.ts.map +0 -1
  253. package/lib/formatter/plainLogFormatter.js +0 -11
  254. package/lib/formatter/plainLogFormatter.js.map +0 -1
  255. package/lib/getDefaultReporter.browser.d.ts +0 -2
  256. package/lib/getDefaultReporter.browser.d.ts.map +0 -1
  257. package/lib/getDefaultReporter.browser.js +0 -15
  258. package/lib/getDefaultReporter.browser.js.map +0 -1
  259. package/lib/getDefaultReporter.d.ts +0 -2
  260. package/lib/getDefaultReporter.d.ts.map +0 -1
  261. package/lib/getDefaultReporter.js +0 -19
  262. package/lib/getDefaultReporter.js.map +0 -1
  263. package/lib/getLogModeFromEnvironment.browser.d.ts +0 -3
  264. package/lib/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  265. package/lib/getLogModeFromEnvironment.browser.js +0 -9
  266. package/lib/getLogModeFromEnvironment.browser.js.map +0 -1
  267. package/lib/getLogModeFromEnvironment.d.ts +0 -3
  268. package/lib/getLogModeFromEnvironment.d.ts.map +0 -1
  269. package/lib/getLogModeFromEnvironment.js +0 -17
  270. package/lib/getLogModeFromEnvironment.js.map +0 -1
  271. package/lib/getLogger.d.ts +0 -9
  272. package/lib/getLogger.d.ts.map +0 -1
  273. package/lib/getLogger.js +0 -95
  274. package/lib/getLogger.js.map +0 -1
  275. package/lib/getLoggers.d.ts +0 -7
  276. package/lib/getLoggers.d.ts.map +0 -1
  277. package/lib/getLoggers.js +0 -15
  278. package/lib/getLoggers.js.map +0 -1
  279. package/lib/index.d.ts +0 -17
  280. package/lib/index.d.ts.map +0 -1
  281. package/lib/index.js +0 -20
  282. package/lib/index.js.map +0 -1
  283. package/lib/logLevel.d.ts +0 -106
  284. package/lib/logLevel.d.ts.map +0 -1
  285. package/lib/logLevel.js +0 -59
  286. package/lib/logLevel.js.map +0 -1
  287. package/lib/logLevelFn.d.ts +0 -20
  288. package/lib/logLevelFn.d.ts.map +0 -1
  289. package/lib/logLevelFn.js +0 -76
  290. package/lib/logLevelFn.js.map +0 -1
  291. package/lib/logReporter.d.ts +0 -7
  292. package/lib/logReporter.d.ts.map +0 -1
  293. package/lib/logReporter.js +0 -29
  294. package/lib/logReporter.js.map +0 -1
  295. package/lib/logReporterInternal.d.ts +0 -3
  296. package/lib/logReporterInternal.d.ts.map +0 -1
  297. package/lib/logReporterInternal.js +0 -23
  298. package/lib/logReporterInternal.js.map +0 -1
  299. package/lib/memory/MemoryLogReporter.d.ts.map +0 -1
  300. package/lib/memory/MemoryLogReporter.js +0 -56
  301. package/lib/memory/MemoryLogReporter.js.map +0 -1
  302. package/lib/memory/index.d.ts +0 -3
  303. package/lib/memory/index.d.ts.map +0 -1
  304. package/lib/memory/index.js +0 -6
  305. package/lib/memory/index.js.map +0 -1
  306. package/lib/memory/logEntriesToString.d.ts +0 -3
  307. package/lib/memory/logEntriesToString.d.ts.map +0 -1
  308. package/lib/memory/logEntriesToString.js +0 -10
  309. package/lib/memory/logEntriesToString.js.map +0 -1
  310. package/lib/memory/toInspectStringForObject.d.ts +0 -3
  311. package/lib/memory/toInspectStringForObject.d.ts.map +0 -1
  312. package/lib/memory/toInspectStringForObject.js +0 -15
  313. package/lib/memory/toInspectStringForObject.js.map +0 -1
  314. package/lib/shouldLog.d.ts +0 -8
  315. package/lib/shouldLog.d.ts.map +0 -1
  316. package/lib/shouldLog.js +0 -14
  317. package/lib/shouldLog.js.map +0 -1
  318. package/lib/store.d.ts +0 -3
  319. package/lib/store.d.ts.map +0 -1
  320. package/lib/store.js +0 -17
  321. package/lib/store.js.map +0 -1
  322. package/lib/suppressLogs.d.ts +0 -6
  323. package/lib/suppressLogs.d.ts.map +0 -1
  324. package/lib/suppressLogs.js +0 -17
  325. package/lib/suppressLogs.js.map +0 -1
  326. package/lib/testUtil.d.ts +0 -7
  327. package/lib/testUtil.d.ts.map +0 -1
  328. package/lib/testUtil.js +0 -23
  329. package/lib/testUtil.js.map +0 -1
  330. package/lib/types.d.ts.map +0 -1
  331. package/lib/types.js +0 -3
  332. package/lib/types.js.map +0 -1
  333. package/lib/typesInternal.d.ts +0 -20
  334. package/lib/typesInternal.d.ts.map +0 -1
  335. package/lib/typesInternal.js +0 -3
  336. package/lib/typesInternal.js.map +0 -1
  337. package/lib/utils.d.ts +0 -5
  338. package/lib/utils.d.ts.map +0 -1
  339. package/lib/utils.js +0 -14
  340. package/lib/utils.js.map +0 -1
  341. package/lib/writeToReporters.d.ts +0 -6
  342. package/lib/writeToReporters.d.ts.map +0 -1
  343. package/lib/writeToReporters.js +0 -22
  344. package/lib/writeToReporters.js.map +0 -1
  345. package/libm/LogEntry.d.ts +0 -7
  346. package/libm/LogEntry.d.ts.map +0 -1
  347. package/libm/LogEntry.js +0 -2
  348. package/libm/LogEntry.js.map +0 -1
  349. package/libm/captureLogs.d.ts +0 -4
  350. package/libm/captureLogs.d.ts.map +0 -1
  351. package/libm/captureLogs.js +0 -29
  352. package/libm/captureLogs.js.map +0 -1
  353. package/libm/config.d.ts +0 -12
  354. package/libm/config.d.ts.map +0 -1
  355. package/libm/config.js +0 -44
  356. package/libm/config.js.map +0 -1
  357. package/libm/configForTest.d.ts +0 -5
  358. package/libm/configForTest.d.ts.map +0 -1
  359. package/libm/configForTest.js +0 -14
  360. package/libm/configForTest.js.map +0 -1
  361. package/libm/console/createConsoleLogReporter.d.ts.map +0 -1
  362. package/libm/console/createConsoleLogReporter.js +0 -37
  363. package/libm/console/createConsoleLogReporter.js.map +0 -1
  364. package/libm/console/index.d.ts +0 -4
  365. package/libm/console/index.d.ts.map +0 -1
  366. package/libm/console/index.js +0 -4
  367. package/libm/console/index.js.map +0 -1
  368. package/libm/console/isConsoleDebugAvailable.d.ts +0 -2
  369. package/libm/console/isConsoleDebugAvailable.d.ts.map +0 -1
  370. package/libm/console/isConsoleDebugAvailable.js +0 -13
  371. package/libm/console/isConsoleDebugAvailable.js.map +0 -1
  372. package/libm/console/polyfilledConsole.d.ts +0 -7
  373. package/libm/console/polyfilledConsole.d.ts.map +0 -1
  374. package/libm/console/polyfilledConsole.js.map +0 -1
  375. package/libm/console/semverGt.d.ts +0 -2
  376. package/libm/console/semverGt.d.ts.map +0 -1
  377. package/libm/console/semverGt.js +0 -9
  378. package/libm/console/semverGt.js.map +0 -1
  379. package/libm/console/toConsoleMethod.d.ts +0 -2
  380. package/libm/console/toConsoleMethod.d.ts.map +0 -1
  381. package/libm/console/toConsoleMethod.js +0 -18
  382. package/libm/console/toConsoleMethod.js.map +0 -1
  383. package/libm/console/types.d.ts +0 -3
  384. package/libm/console/types.d.ts.map +0 -1
  385. package/libm/console/types.js.map +0 -1
  386. package/libm/customLogLevel.d.ts +0 -11
  387. package/libm/customLogLevel.d.ts.map +0 -1
  388. package/libm/customLogLevel.js +0 -30
  389. package/libm/customLogLevel.js.map +0 -1
  390. package/libm/errors.d.ts +0 -19
  391. package/libm/errors.d.ts.map +0 -1
  392. package/libm/errors.js +0 -32
  393. package/libm/errors.js.map +0 -1
  394. package/libm/formatter/createTimestampFormatter.d.ts +0 -3
  395. package/libm/formatter/createTimestampFormatter.d.ts.map +0 -1
  396. package/libm/formatter/createTimestampFormatter.js.map +0 -1
  397. package/libm/formatter/formatLogLevel.d.ts +0 -2
  398. package/libm/formatter/formatLogLevel.d.ts.map +0 -1
  399. package/libm/formatter/formatLogLevel.js +0 -6
  400. package/libm/formatter/formatLogLevel.js.map +0 -1
  401. package/libm/formatter/index.d.ts +0 -4
  402. package/libm/formatter/index.d.ts.map +0 -1
  403. package/libm/formatter/index.js +0 -4
  404. package/libm/formatter/index.js.map +0 -1
  405. package/libm/formatter/plainLogFormatter.d.ts +0 -3
  406. package/libm/formatter/plainLogFormatter.d.ts.map +0 -1
  407. package/libm/formatter/plainLogFormatter.js +0 -5
  408. package/libm/formatter/plainLogFormatter.js.map +0 -1
  409. package/libm/getDefaultReporter.browser.d.ts +0 -2
  410. package/libm/getDefaultReporter.browser.d.ts.map +0 -1
  411. package/libm/getDefaultReporter.browser.js +0 -11
  412. package/libm/getDefaultReporter.browser.js.map +0 -1
  413. package/libm/getDefaultReporter.d.ts +0 -2
  414. package/libm/getDefaultReporter.d.ts.map +0 -1
  415. package/libm/getDefaultReporter.js +0 -15
  416. package/libm/getDefaultReporter.js.map +0 -1
  417. package/libm/getLogModeFromEnvironment.browser.d.ts +0 -3
  418. package/libm/getLogModeFromEnvironment.browser.d.ts.map +0 -1
  419. package/libm/getLogModeFromEnvironment.browser.js +0 -5
  420. package/libm/getLogModeFromEnvironment.browser.js.map +0 -1
  421. package/libm/getLogModeFromEnvironment.d.ts +0 -3
  422. package/libm/getLogModeFromEnvironment.d.ts.map +0 -1
  423. package/libm/getLogModeFromEnvironment.js +0 -13
  424. package/libm/getLogModeFromEnvironment.js.map +0 -1
  425. package/libm/getLogger.d.ts +0 -9
  426. package/libm/getLogger.d.ts.map +0 -1
  427. package/libm/getLogger.js +0 -78
  428. package/libm/getLogger.js.map +0 -1
  429. package/libm/getLoggers.d.ts +0 -7
  430. package/libm/getLoggers.d.ts.map +0 -1
  431. package/libm/getLoggers.js +0 -11
  432. package/libm/getLoggers.js.map +0 -1
  433. package/libm/index.d.ts +0 -17
  434. package/libm/index.d.ts.map +0 -1
  435. package/libm/index.js +0 -17
  436. package/libm/index.js.map +0 -1
  437. package/libm/logLevel.d.ts +0 -106
  438. package/libm/logLevel.d.ts.map +0 -1
  439. package/libm/logLevel.js.map +0 -1
  440. package/libm/logLevelFn.d.ts +0 -20
  441. package/libm/logLevelFn.d.ts.map +0 -1
  442. package/libm/logLevelFn.js +0 -67
  443. package/libm/logLevelFn.js.map +0 -1
  444. package/libm/logReporter.d.ts +0 -7
  445. package/libm/logReporter.d.ts.map +0 -1
  446. package/libm/logReporter.js +0 -21
  447. package/libm/logReporter.js.map +0 -1
  448. package/libm/logReporterInternal.d.ts +0 -3
  449. package/libm/logReporterInternal.d.ts.map +0 -1
  450. package/libm/logReporterInternal.js +0 -19
  451. package/libm/logReporterInternal.js.map +0 -1
  452. package/libm/memory/MemoryLogReporter.d.ts.map +0 -1
  453. package/libm/memory/MemoryLogReporter.js +0 -51
  454. package/libm/memory/MemoryLogReporter.js.map +0 -1
  455. package/libm/memory/index.d.ts +0 -3
  456. package/libm/memory/index.d.ts.map +0 -1
  457. package/libm/memory/index.js +0 -3
  458. package/libm/memory/index.js.map +0 -1
  459. package/libm/memory/logEntriesToString.d.ts +0 -3
  460. package/libm/memory/logEntriesToString.d.ts.map +0 -1
  461. package/libm/memory/logEntriesToString.js +0 -6
  462. package/libm/memory/logEntriesToString.js.map +0 -1
  463. package/libm/memory/toInspectStringForObject.d.ts +0 -3
  464. package/libm/memory/toInspectStringForObject.d.ts.map +0 -1
  465. package/libm/memory/toInspectStringForObject.js +0 -11
  466. package/libm/memory/toInspectStringForObject.js.map +0 -1
  467. package/libm/shouldLog.d.ts +0 -8
  468. package/libm/shouldLog.d.ts.map +0 -1
  469. package/libm/shouldLog.js +0 -10
  470. package/libm/shouldLog.js.map +0 -1
  471. package/libm/store.d.ts +0 -3
  472. package/libm/store.d.ts.map +0 -1
  473. package/libm/store.js +0 -24
  474. package/libm/store.js.map +0 -1
  475. package/libm/suppressLogs.d.ts +0 -6
  476. package/libm/suppressLogs.d.ts.map +0 -1
  477. package/libm/suppressLogs.js +0 -9
  478. package/libm/suppressLogs.js.map +0 -1
  479. package/libm/testUtil.d.ts +0 -7
  480. package/libm/testUtil.d.ts.map +0 -1
  481. package/libm/testUtil.js +0 -17
  482. package/libm/testUtil.js.map +0 -1
  483. package/libm/types.d.ts.map +0 -1
  484. package/libm/types.js +0 -2
  485. package/libm/types.js.map +0 -1
  486. package/libm/typesInternal.d.ts +0 -20
  487. package/libm/typesInternal.d.ts.map +0 -1
  488. package/libm/typesInternal.js +0 -2
  489. package/libm/typesInternal.js.map +0 -1
  490. package/libm/utils.d.ts +0 -5
  491. package/libm/utils.d.ts.map +0 -1
  492. package/libm/utils.js +0 -10
  493. package/libm/utils.js.map +0 -1
  494. package/libm/writeToReporters.d.ts +0 -6
  495. package/libm/writeToReporters.d.ts.map +0 -1
  496. package/libm/writeToReporters.js +0 -18
  497. package/libm/writeToReporters.js.map +0 -1
  498. package/src/LogEntry.ts +0 -7
  499. package/src/captureLogs.spec.ts +0 -52
  500. package/src/captureLogs.ts +0 -35
  501. package/src/config.spec.ts +0 -80
  502. package/src/config.ts +0 -57
  503. package/src/configForTest.spec.ts +0 -16
  504. package/src/configForTest.ts +0 -16
  505. package/src/console/createConsoleLogReporter.spec.ts +0 -198
  506. package/src/console/createConsoleLogReporter.ts +0 -42
  507. package/src/console/index.ts +0 -3
  508. package/src/console/isConsoleDebugAvailable.ts +0 -11
  509. package/src/console/polyfilledConsole.ts +0 -34
  510. package/src/console/semverGt.spec.ts +0 -25
  511. package/src/console/semverGt.ts +0 -9
  512. package/src/console/toConsoleMethod.ts +0 -18
  513. package/src/console/types.ts +0 -3
  514. package/src/customLogLevel.spec.ts +0 -39
  515. package/src/customLogLevel.ts +0 -35
  516. package/src/errors.ts +0 -24
  517. package/src/formatter/createTimestampFormatter.spec.ts +0 -24
  518. package/src/formatter/formatLogLevel.ts +0 -6
  519. package/src/formatter/index.ts +0 -3
  520. package/src/formatter/plainLogFormatter.spec.ts +0 -8
  521. package/src/formatter/plainLogFormatter.ts +0 -6
  522. package/src/getDefaultReporter.browser.ts +0 -13
  523. package/src/getDefaultReporter.ts +0 -15
  524. package/src/getLogModeFromEnvironment.browser.ts +0 -6
  525. package/src/getLogModeFromEnvironment.spec.ts +0 -16
  526. package/src/getLogModeFromEnvironment.ts +0 -16
  527. package/src/getLogger.spec.ts +0 -460
  528. package/src/getLogger.ts +0 -92
  529. package/src/getLoggers.ts +0 -12
  530. package/src/index.ts +0 -16
  531. package/src/logLevel.spec.ts +0 -161
  532. package/src/logLevelFn.ts +0 -72
  533. package/src/logReporter.spec.ts +0 -99
  534. package/src/logReporter.ts +0 -26
  535. package/src/logReporterInternal.ts +0 -18
  536. package/src/memory/MemoryLogReporter.spec.ts +0 -114
  537. package/src/memory/MemoryLogReporter.ts +0 -66
  538. package/src/memory/index.ts +0 -2
  539. package/src/memory/logEntriesToString.spec.ts +0 -47
  540. package/src/memory/logEntriesToString.ts +0 -7
  541. package/src/memory/toInspectStringForObject.ts +0 -13
  542. package/src/shouldLog.ts +0 -11
  543. package/src/store.ts +0 -25
  544. package/src/suppressLogs.spec.ts +0 -34
  545. package/src/suppressLogs.ts +0 -14
  546. package/src/testUtil.ts +0 -19
  547. package/src/types.spec.ts +0 -7
  548. package/src/typesInternal.ts +0 -21
  549. package/src/utils.ts +0 -9
  550. package/src/writeToReporters.spec.ts +0 -9
  551. package/src/writeToReporters.ts +0 -20
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 unional, Homa Wong (homawong@gmail.com)
3
+ Copyright © 2017 unional, Homa Wong (homawong@gmail.com)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -3,50 +3,61 @@
3
3
  [![NPM version][npm-image]][npm-url]
4
4
  [![NPM downloads][downloads-image]][downloads-url]
5
5
 
6
- [![Github NodeJS][github-nodejs]][github-action-url]
6
+ [![GitHub NodeJS][github-nodejs]][github-action-url]
7
7
  [![Codecov][codecov-image]][codecov-url]
8
- [![Codacy Grade Badge][codacy-grade]][codacy-grade-url]
9
- [![Codacy Coverage Badge][codacy-coverage]][codacy-coverage-url]
10
-
11
- [![Greenkeeper][greenkeeper-image]][greenkeeper-url]
12
8
 
13
9
  [![Visual Studio Code][vscode-image]][vscode-url]
14
- [![Wallaby.js][wallaby-image]][wallaby-url]
15
10
 
16
- `standard-log` is a powerful and extensible logging library.
11
+ [`standard-log`] is a powerful and extensible logging library.
12
+
13
+ ## New in 9.0
14
+
15
+ [`standard-log`] 9.0 is a trimmed down version that focus more on security and support the micro-app paradigm.
16
+
17
+ The key changes are:
18
+
19
+ - No side effects: application calling `createStandardLog()` gets a completely enclosed log system.
20
+ - Immutable: after the log system can be configured when calling `createStandardLog()`.\
21
+ But after that, the system is immutable and cannot be changed.\
22
+
23
+ For the full list of changes, please check the [change log](./CHANGELOG.md).
17
24
 
18
25
  ## Key features
19
26
 
20
- - create multiple loggers for different part of your application.
21
- - provide multiple log levels out of the box.
22
- - add custom log levels.
23
- - global and local log level control.
24
- - send logs to multiple reporters, e.g. console, file, memory, or remote service.
25
- - custom formatting and filtering for each reporter.
26
- - config tempering protection during production
27
+ - Support micro-app with isolated log system.
28
+ - Create multiple loggers for different part of your application.
29
+ - Provide multiple log levels out of the box.
30
+ - Support custom log levels.
31
+ - Three levels of log level controls: log system, logger, and log method.
32
+ - Send logs to multiple reporters, e.g. console, file, memory, or remote service.
33
+ - Custom formatting and filtering for each reporter.
34
+ - Security focus. After the system is created, it cannot be changed.
35
+ - Compliant with the [`just-func`] paradigm.
27
36
 
28
37
  ## Usage
29
38
 
30
- To use `standard-log`, simply create your logger and log away:
39
+ To use [`standard-log`], you first create a new log system.
31
40
 
32
41
  ```ts
33
- import { getLogger } from 'standard-log'
42
+ import { createStandardLog } from 'standard-log'
43
+
44
+ const standardLog = createStandarLog(/* options */)
34
45
 
35
- const log = getLogger('my-app')
46
+ const log = standardLog.getLogger(['my-app'])
36
47
 
37
- log.error('error')
38
- log.warn('warn')
39
- log.info('info')
48
+ log.error('error message')
49
+ log.warn('warn message')
50
+ log.info('info message')
40
51
  // by default debug() will not be printed
41
52
  // because production mode defaults log level to `info`
42
- log.debug('debug')
53
+ log.debug('debug message')
43
54
  ```
44
55
 
45
- ![rendering-example](images/2019-08-08-23-40-05.png)
56
+ ![Rendering example](images/2022-06-10-19-21-48.png)
46
57
 
47
- (above is logged with `standard-log-color` installed)
58
+ (above is logged with `standard-log-color`)
48
59
 
49
- You can configure a logger by doing `getLogger(id, options)`:
60
+ You can configure a logger by doing `getLogger([id, options])`:
50
61
 
51
62
  `options.level: number`:
52
63
 
@@ -56,41 +67,12 @@ Log level of this logger.
56
67
 
57
68
  Only log to specific reporter(s).
58
69
 
59
- ### Mode
60
-
61
- By default, `standard-log` runs in production mode.
62
- You can change it programmatically:
63
-
64
- ```ts
65
- import { config } from 'standard-log'
66
-
67
- config({ mode: 'production' }) // or 'development', 'test'
68
- ```
69
-
70
- or by setting the environment variable `STANDARD_LOG`.
71
-
72
- `production` mode:
73
-
74
- - `config()` can only be called once.
75
- - configuration is protected from tempering.
76
-
77
- `development` mode:
78
-
79
- - a warning is emitted when calling `config()` or log for the first time.
80
-
81
- `test` mode:
82
-
83
- - no warning is emitted
84
-
85
70
  ### Log Level
86
71
 
87
72
  `standard-log` log level defaults to `logLevels.info`.
88
73
  It comes with many log levels out of the box:
89
74
 
90
75
  ```ts
91
- import { getLogger } from 'standard-log'
92
-
93
- const log = getLogger('x')
94
76
  log.emergency('msg')
95
77
  log.alert('msg')
96
78
  log.critical('msg')
@@ -108,16 +90,16 @@ When sending logs to console, they are mapped to `info`, `warn`, `error`, and `d
108
90
  You can also add your own custom levels:
109
91
 
110
92
  ```ts
111
- import { config, getLogger, logLevel } from 'standard-log'
93
+ import { createStandardLog } from 'standard-log'
112
94
 
113
- config({
95
+ const standardLog = createStandardLog({
114
96
  customLevels: {
115
97
  'important': logLevel.warn + 1,
116
98
  'silly': logLevel.debug + 1
117
99
  }
118
100
  })
119
101
 
120
- const log = getLogger<'silly' | 'important'>('custom')
102
+ const log = standardLog.getLogger('custom')
121
103
  log.important('this is an important message')
122
104
  log.silly('oh silly')
123
105
  ```
@@ -128,14 +110,14 @@ Besides printing the logs to console,
128
110
  you can use different reporters to save the logs in memory, file, service, or others.
129
111
 
130
112
  ```ts
131
- import { config, createConsoleLogReporter, createMemoryLogReporter } from 'standard-log'
113
+ import { createStandardLog, createConsoleLogReporter, createMemoryLogReporter } from 'standard-log'
132
114
 
133
- config({
115
+ createStandardLog({
134
116
  reporters: [createConsoleLogReporter(), createMemoryLogReporter()]
135
117
  })
136
118
  ```
137
119
 
138
- Some reporters allows you to format the logs and/or filter them.
120
+ Some reporters allow you to format the logs and/or filter them.
139
121
  Using the console log reporter as an example:
140
122
 
141
123
  ```ts
@@ -149,37 +131,10 @@ createConsoleLogReporter({
149
131
 
150
132
  Here are some additional reporters:
151
133
 
152
- - [`standard-log-color`](https://github.com/unional/standard-log/tree/master/packages/color)
134
+ - [`standard-log-color`]
153
135
  - `standard-log-file` (TODO)
154
136
  - `standard-log-syslog` (TODO)
155
137
 
156
- ### Capture Logs
157
-
158
- You can temporarily capture logs by `captureLogs()`.
159
- This is useful when you are writing tests.
160
-
161
- ```ts
162
- import { getLogger, captureLogs } from 'standard-log'
163
- import a from 'assertron'
164
-
165
- test('your test', () => {
166
- function foo() {
167
- const log = getLogger('foo logger')
168
- // this log will not be sent to normal reporters
169
- log.info('some messages')
170
- return 'miku'
171
- }
172
- const log = getLogger('foo logger')
173
- const [result, logs] = captureLogs(log, foo)
174
-
175
- a.satisfies(logs, [{ args: ['some messages']}])
176
- a.equals('miku', result)
177
-
178
- // rewriting the logs
179
- logs.forEach(entry => log.write(entry))
180
- })
181
- ```
182
-
183
138
  ### Suppress log
184
139
 
185
140
  You can temporarily suppress logs by `suppressLogs()`.
@@ -193,66 +148,35 @@ const log = getLogger('some logger')
193
148
  suppressLogs(() => log.info('not logged'), log)
194
149
  ```
195
150
 
196
- ## Browser usage
197
-
198
- The package comes with a pre-bundled file under `dist`.
199
- To use it, you also need to load [`global-store`](https://github.com/unional/global-store)
200
-
201
- If you are building a library and bundle it, make sure you mark `global-store` as externals.
202
- You can check out [`global-store`](https://github.com/unional/global-store) for more information.
203
-
204
- ## testing
151
+ ## Testing
205
152
 
206
153
  During test,
207
- you should configure `standard-log` to `test` mode and use `MemoryReporter` to capture the logs.
154
+ you should use `createStandardLogForTest` which includes a `MemoryReporter` to capture the logs.
208
155
 
209
156
  ```ts
210
- import { config, createMemoryReporter } from 'standard-log'
157
+ import { createStandardLogForTest, createMemoryReporter } from 'standard-log'
211
158
 
212
159
  test('your test', () => {
213
- const reporter = createMemoryLogReporter()
214
- config({
215
- reporters: [reporter],
216
- mode: 'test'
217
- })
160
+ const standardLog = createStandardLogForTest()
161
+ yourApp.standardLog = standardLog
218
162
 
219
- // do your thing...
163
+ // do your thing...
220
164
 
221
- const messages = reporter.getLogMessage() // or getLogMessageWithLevel()
165
+ const messages = standardLog.reporter.getLogMessage() // or getLogMessageWithLevel()
222
166
  // validate the message if you want to
223
167
  })
224
168
  ```
225
169
 
226
- And to simplify things, you can use the `configForTest()` function:
227
-
228
- ```ts
229
- import { configForTest } from 'standard-log'
230
-
231
- test('your test', () => {
232
- const { reporter } = configForTest()
233
-
234
- // do your thing...
235
- })
236
- ```
237
-
238
- [npm-image]: https://img.shields.io/npm/v/standard-log.svg?style=flat
239
- [npm-url]: https://www.npmjs.com/package/standard-log
170
+ [`just-func`]: https://github.com/justland/just-func-typescript
171
+ [`standard-log`]: https://github.com/unional/standard-log
172
+ [`standard-log-color`]: https://github.com/unional/standard-log/tree/master/packages/color
173
+ [codecov-image]: https://codecov.io/gh/unional/standard-log/branch/master/graph/badge.svg
174
+ [codecov-url]: https://codecov.io/gh/unional/standard-log
240
175
  [downloads-image]: https://img.shields.io/npm/dm/standard-log.svg?style=flat
241
176
  [downloads-url]: https://npmjs.org/package/standard-log
242
-
243
- [github-nodejs]: https://github.com/unional/standard-log/workflows/Node%20CI/badge.svg
244
177
  [github-action-url]: https://github.com/unional/standard-log/actions
245
- [codecov-image]: https://codecov.io/gh/unional/standard-log/branch/master/graph/badge.svg
246
- [codecov-url]: https://codecov.io/gh/unional/standard-log
247
- [codacy-grade]: https://api.codacy.com/project/badge/Grade/707f89609508442486050d207ec5bd78
248
- [codacy-grade-url]: https://www.codacy.com/app/homawong/standard-log?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=unional/standard-log&amp;utm_campaign=Badge_Grade
249
- [codacy-coverage]: https://api.codacy.com/project/badge/Coverage/707f89609508442486050d207ec5bd78
250
- [codacy-coverage-url]: https://www.codacy.com/manual/homawong/standard-log?utm_source=github.com&utm_medium=referral&utm_content=unional/standard-log&utm_campaign=Badge_Coverage
251
-
252
- [greenkeeper-image]: https://badges.greenkeeper.io/unional/standard-log.svg
253
- [greenkeeper-url]: https://greenkeeper.io/
254
-
178
+ [github-nodejs]: https://github.com/unional/standard-log/workflows/Node%20CI/badge.svg
179
+ [npm-image]: https://img.shields.io/npm/v/standard-log.svg?style=flat
180
+ [npm-url]: https://www.npmjs.com/package/standard-log
255
181
  [vscode-image]: https://img.shields.io/badge/vscode-ready-green.svg
256
182
  [vscode-url]: https://code.visualstudio.com/
257
- [wallaby-image]: https://img.shields.io/badge/wallaby.js-configured-green.svg
258
- [wallaby-url]: https://wallabyjs.com
@@ -1,9 +1,9 @@
1
- import { LogFormatter, LogReporter, LogReporterOptions } from '../types';
2
- import { Console } from './types';
1
+ import type { ConsoleLike, LogFormatter, LogReporter, LogReporterOptions } from './types.js';
2
+ export declare function toConsoleMethod(level: number): "error" | "warn" | "info" | "debug";
3
+ export declare type ConsoleLogFormatter = LogFormatter<any[]>;
3
4
  export declare type ConsoleLogReporter = LogReporter<any[]> & {
4
- console: Console;
5
+ console: ConsoleLike;
5
6
  };
6
- export declare type ConsoleLogFormatter = LogFormatter<any[]>;
7
7
  export declare type ConsoleLogReporterOptions = LogReporterOptions<any[]>;
8
8
  export declare function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter;
9
- //# sourceMappingURL=createConsoleLogReporter.d.ts.map
9
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAY,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEtG,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,uCAS5C;AAmCD,oBAAY,mBAAmB,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,CAAA;AACrD,oBAAY,kBAAkB,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAA;AAC9E,oBAAY,yBAAyB,GAAG,kBAAkB,CAAC,GAAG,EAAE,CAAC,CAAA;AAEjE,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,kBAAkB,CAiBhG"}
package/cjs/console.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConsoleLogReporter = exports.toConsoleMethod = void 0;
4
+ var type_plus_1 = require("type-plus");
5
+ var logLevels_js_1 = require("./logLevels.js");
6
+ var platform_js_1 = require("./platform.js");
7
+ var formatter_js_1 = require("./formatter.js");
8
+ function toConsoleMethod(level) {
9
+ switch (true) {
10
+ // edge case in case none is somehow written
11
+ case (level <= 0): return 'debug';
12
+ case (level <= logLevels_js_1.logLevels.error): return 'error';
13
+ case (level <= logLevels_js_1.logLevels.warn): return 'warn';
14
+ case (level <= logLevels_js_1.logLevels.info): return 'info';
15
+ default: return 'debug';
16
+ }
17
+ }
18
+ exports.toConsoleMethod = toConsoleMethod;
19
+ // istanbul ignore next
20
+ /* eslint-disable no-console */
21
+ function buildPolyfillConsole() {
22
+ // old phantomjs does not have bind function
23
+ var hasBind = !!console.log.bind;
24
+ if (hasBind) {
25
+ return {
26
+ // Node@9.3 or below has `console.debug = undefined` or it doesn't log
27
+ // Should use `console.log()` in those case.
28
+ debug: ((0, platform_js_1.isConsoleDebugAvailable)() ? console.debug : console.log).bind(console),
29
+ // the `typeof` guards against IE where `console.log.apply()`
30
+ // results in error `Object doesn't support property or method 'apply'`
31
+ info: (typeof console.info === 'function' ? console.info : console.log).bind(console),
32
+ warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),
33
+ error: (typeof console.error === 'function' ? console.error : console.log).bind(console)
34
+ };
35
+ }
36
+ else {
37
+ return {
38
+ debug: buildFn((0, platform_js_1.isConsoleDebugAvailable)() ? 'debug' : 'log'),
39
+ info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),
40
+ warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),
41
+ error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),
42
+ };
43
+ }
44
+ }
45
+ // istanbul ignore next
46
+ function buildFn(name) {
47
+ return function () {
48
+ var args = [];
49
+ for (var _i = 0; _i < arguments.length; _i++) {
50
+ args[_i] = arguments[_i];
51
+ }
52
+ console[name].apply(console, args);
53
+ };
54
+ }
55
+ function createConsoleLogReporter(options) {
56
+ var _a = (0, type_plus_1.required)({ id: 'console', formatter: formatter_js_1.plainLogFormatter }, options), id = _a.id, formatter = _a.formatter, filter = _a.filter;
57
+ if (!platform_js_1.polyfill.console)
58
+ platform_js_1.polyfill.console = buildPolyfillConsole();
59
+ return Object.freeze({
60
+ id: id,
61
+ isConsoleReporter: true,
62
+ get formatter() { return formatter; },
63
+ get filter() { return filter; },
64
+ console: platform_js_1.polyfill.console,
65
+ write: function (entry) {
66
+ var _a;
67
+ if (filter && !filter(entry))
68
+ return;
69
+ var values = formatter(entry);
70
+ var method = toConsoleMethod(entry.level);
71
+ (_a = this.console)[method].apply(_a, values);
72
+ }
73
+ });
74
+ }
75
+ exports.createConsoleLogReporter = createConsoleLogReporter;
76
+ //# sourceMappingURL=console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.js","sourceRoot":"","sources":["../ts/console.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,+CAA0C;AAC1C,6CAAiE;AACjE,+CAAkD;AAGlD,SAAgB,eAAe,CAAC,KAAa;IAC3C,QAAQ,IAAI,EAAE;QACZ,4CAA4C;QAC5C,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,OAAO,CAAA;QACjC,KAAK,CAAC,KAAK,IAAI,wBAAS,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,OAAO,CAAA;QAC/C,KAAK,CAAC,KAAK,IAAI,wBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,MAAM,CAAA;QAC7C,KAAK,CAAC,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M,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC3C,CAAA,KAAA,IAAI,CAAC,OAAO,CAAA,CAAC,MAAM,CAAC,WAAI,MAAM,EAAC;QACjC,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAjBD,4DAiBC","sourcesContent":["import { required } from 'type-plus'\nimport { logLevels } from './logLevels.js'\nimport { isConsoleDebugAvailable, polyfill } from './platform.js'\nimport { plainLogFormatter } from './formatter.js'\nimport type { ConsoleLike, LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\n\nexport function toConsoleMethod(level: number) {\n switch (true) {\n // edge case in case none is somehow written\n case (level <= 0): return 'debug'\n case (level <= logLevels.error): return 'error'\n case (level <= logLevels.warn): return 'warn'\n case (level <= logLevels.info): return 'info'\n default: return 'debug'\n }\n}\n\n// istanbul ignore next\n/* eslint-disable no-console */\nfunction buildPolyfillConsole() {\n // old phantomjs does not have bind function\n const hasBind = !!console.log.bind as boolean\n if (hasBind) {\n return {\n // Node@9.3 or below has `console.debug = undefined` or it doesn't log\n // Should use `console.log()` in those case.\n debug: (isConsoleDebugAvailable() ? console.debug : console.log).bind(console),\n // the `typeof` guards against IE where `console.log.apply()`\n // results in error `Object doesn't support property or method 'apply'`\n info: (typeof console.info === 'function' ? console.info : console.log).bind(console),\n warn: (typeof console.warn === 'function' ? console.warn : console.log).bind(console),\n error: (typeof console.error === 'function' ? console.error : console.log).bind(console)\n }\n }\n else {\n return {\n debug: buildFn(isConsoleDebugAvailable() ? 'debug' : 'log'),\n info: buildFn(typeof console.info === 'function' ? 'info' : 'log'),\n warn: buildFn(typeof console.warn === 'function' ? 'warn' : 'log'),\n error: buildFn(typeof console.error === 'function' ? 'error' : 'log'),\n }\n }\n}\n\n// istanbul ignore next\nfunction buildFn(name: 'debug' | 'info' | 'warn' | 'error' | 'log') {\n return function (...args: any[]) { console[name](...args) }\n}\n\n\nexport type ConsoleLogFormatter = LogFormatter<any[]>\nexport type ConsoleLogReporter = LogReporter<any[]> & { console: ConsoleLike }\nexport type ConsoleLogReporterOptions = LogReporterOptions<any[]>\n\nexport function createConsoleLogReporter(options?: ConsoleLogReporterOptions): ConsoleLogReporter {\n const { id, formatter, filter } = required({ id: 'console', formatter: plainLogFormatter }, options)\n if (!polyfill.console) polyfill.console = buildPolyfillConsole()\n\n return Object.freeze({\n id,\n isConsoleReporter: true,\n get formatter() { return formatter },\n get filter() { return filter },\n console: polyfill.console,\n write(entry: LogEntry) {\n if (filter && !filter(entry)) return\n const values = formatter(entry)\n const method = toConsoleMethod(entry.level)\n this.console[method](...values)\n }\n })\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=console.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.spec.d.ts","sourceRoot":"","sources":["../ts/console.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var standardLog_js_1 = require("./standardLog.js");
4
+ var index_js_1 = require("./index.js");
5
+ var platform_js_1 = require("./platform.js");
6
+ describe('toConsoleMethod()', function () {
7
+ it('converts any level to standard console method names: debug, info, warn, error', function () {
8
+ expect((0, index_js_1.toConsoleMethod)(1)).toEqual('error');
9
+ expect((0, index_js_1.toConsoleMethod)(399)).toEqual('error');
10
+ expect((0, index_js_1.toConsoleMethod)(400)).toEqual('error');
11
+ expect((0, index_js_1.toConsoleMethod)(401)).toEqual('warn');
12
+ expect((0, index_js_1.toConsoleMethod)(499)).toEqual('warn');
13
+ expect((0, index_js_1.toConsoleMethod)(500)).toEqual('warn');
14
+ expect((0, index_js_1.toConsoleMethod)(501)).toEqual('info');
15
+ expect((0, index_js_1.toConsoleMethod)(700)).toEqual('info');
16
+ expect((0, index_js_1.toConsoleMethod)(701)).toEqual('debug');
17
+ expect((0, index_js_1.toConsoleMethod)(800)).toEqual('debug');
18
+ expect((0, index_js_1.toConsoleMethod)(801)).toEqual('debug');
19
+ expect((0, index_js_1.toConsoleMethod)(Infinity)).toEqual('debug');
20
+ });
21
+ it('converts to debug for 0 (none) or negative (not valid) level', function () {
22
+ // these are invalid input.
23
+ // so instead of hiding them and not logged,
24
+ // log them so that it is easier to discover.
25
+ expect((0, index_js_1.toConsoleMethod)(-1)).toEqual('debug');
26
+ expect((0, index_js_1.toConsoleMethod)(0)).toEqual('debug');
27
+ });
28
+ });
29
+ describe('rendering tests', function () {
30
+ test('plain rendering', function () {
31
+ var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: index_js_1.plainLogFormatter });
32
+ ['emergency', 'info', 'warn', 'debug'].forEach(function (level) {
33
+ reporter.write({ id: 'plain', level: index_js_1.logLevels[level], args: ['hello', 'world'], timestamp: new Date() });
34
+ });
35
+ });
36
+ });
37
+ describe('createConsoleLogReporter', function () {
38
+ var fakeConsole = createFakeConsole();
39
+ beforeEach(function () { return platform_js_1.polyfill.console = fakeConsole = createFakeConsole(); });
40
+ describe('id', function () {
41
+ test('default is "console"', function () {
42
+ var reporter = (0, index_js_1.createConsoleLogReporter)();
43
+ expect(reporter.id).toBe('console');
44
+ });
45
+ test('can be overridden', function () {
46
+ var reporter = (0, index_js_1.createConsoleLogReporter)({ id: 'neo-console' });
47
+ expect(reporter.id).toBe('neo-console');
48
+ });
49
+ });
50
+ describe('log level', function () {
51
+ test('error, alert, critical and emergency logs are written to console.error', function () {
52
+ var id = 'log';
53
+ var reporter = (0, index_js_1.createConsoleLogReporter)();
54
+ reporter.write({ id: id, level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
55
+ reporter.write({ id: id, level: index_js_1.logLevels.critical, args: ['critical'], timestamp: new Date() });
56
+ reporter.write({ id: id, level: index_js_1.logLevels.alert, args: ['alert'], timestamp: new Date() });
57
+ reporter.write({ id: id, level: index_js_1.logLevels.error, args: ['error'], timestamp: new Date() });
58
+ expect(fakeConsole.errors.length).toBe(4);
59
+ });
60
+ test('warn logs are written to console.warn', function () {
61
+ var id = 'log';
62
+ var reporter = (0, index_js_1.createConsoleLogReporter)();
63
+ reporter.write({ id: id, level: index_js_1.logLevels.warn, args: ['warn'], timestamp: new Date() });
64
+ expect(fakeConsole.warns.length).toBe(1);
65
+ });
66
+ test('notice and info logs are written to console.info', function () {
67
+ var id = 'log';
68
+ var reporter = (0, index_js_1.createConsoleLogReporter)();
69
+ reporter.write({ id: id, level: index_js_1.logLevels.notice, args: ['notice'], timestamp: new Date() });
70
+ reporter.write({ id: id, level: index_js_1.logLevels.info, args: ['info'], timestamp: new Date() });
71
+ expect(fakeConsole.infos.length).toBe(2);
72
+ });
73
+ test('debug, trace, and planck logs are written to console.debug', function () {
74
+ var id = 'log';
75
+ var reporter = (0, index_js_1.createConsoleLogReporter)();
76
+ reporter.write({ id: id, level: index_js_1.logLevels.debug, args: ['debug'], timestamp: new Date() });
77
+ reporter.write({ id: id, level: index_js_1.logLevels.trace, args: ['trace'], timestamp: new Date() });
78
+ reporter.write({ id: id, level: index_js_1.logLevels.planck, args: ['planck'], timestamp: new Date() });
79
+ expect(fakeConsole.debugs.length).toBe(3);
80
+ });
81
+ });
82
+ describe('custom logs', function () {
83
+ test('are written according to their log level value', function () {
84
+ var id = 'log';
85
+ var reporter = (0, index_js_1.createConsoleLogReporter)();
86
+ var sl = (0, standardLog_js_1.createStandardLog)({
87
+ logLevel: index_js_1.logLevels.all,
88
+ customLevels: {
89
+ 'high': 50,
90
+ 'important': 450,
91
+ 'interest': 650,
92
+ 'silly': 1000
93
+ },
94
+ reporters: [reporter]
95
+ });
96
+ var log = sl.getLogger([id]);
97
+ log.high('a');
98
+ log.important('b');
99
+ log.interest('c');
100
+ log.silly('d');
101
+ expect(fakeConsole.errors.length).toBe(1);
102
+ expect(fakeConsole.warns.length).toBe(1);
103
+ expect(fakeConsole.infos.length).toBe(1);
104
+ expect(fakeConsole.debugs.length).toBe(1);
105
+ });
106
+ });
107
+ var idFormatter = function (entry) { return [entry.id]; };
108
+ describe('formatter', function () {
109
+ test('use specific formatter', function () {
110
+ var id = 'id-only';
111
+ var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: idFormatter });
112
+ expect(reporter.formatter).toBe(idFormatter);
113
+ reporter.write({ id: id, level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
114
+ expect(fakeConsole.errors).toEqual([['id-only']]);
115
+ });
116
+ });
117
+ describe('filter', function () {
118
+ var filter = function (entry) { return entry.id !== 'secret'; };
119
+ test('use specific filter', function () {
120
+ var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: idFormatter, filter: filter });
121
+ expect(reporter.filter).toBe(filter);
122
+ reporter.write({ id: 'normal', level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
123
+ reporter.write({ id: 'secret', level: index_js_1.logLevels.emergency, args: ['emergency'], timestamp: new Date() });
124
+ expect(fakeConsole.errors).toEqual([['normal']]);
125
+ });
126
+ });
127
+ test('write log entry with multiple arguments', function () {
128
+ var id = 'log';
129
+ var reporter = (0, index_js_1.createConsoleLogReporter)({ formatter: index_js_1.plainLogFormatter });
130
+ var entry = { id: id, level: index_js_1.logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() };
131
+ reporter.write(entry);
132
+ expect(fakeConsole.infos).toEqual([
133
+ [entry.timestamp.toISOString(), 'log', '(INFO)', 'a', 'b', 'c']
134
+ ]);
135
+ });
136
+ });
137
+ function createFakeConsole() {
138
+ var errors = [];
139
+ var infos = [];
140
+ var warns = [];
141
+ var debugs = [];
142
+ return {
143
+ errors: errors,
144
+ infos: infos,
145
+ warns: warns,
146
+ debugs: debugs,
147
+ error: function () {
148
+ var args = [];
149
+ for (var _i = 0; _i < arguments.length; _i++) {
150
+ args[_i] = arguments[_i];
151
+ }
152
+ errors.push(args);
153
+ },
154
+ info: function () {
155
+ var args = [];
156
+ for (var _i = 0; _i < arguments.length; _i++) {
157
+ args[_i] = arguments[_i];
158
+ }
159
+ infos.push(args);
160
+ },
161
+ warn: function () {
162
+ var args = [];
163
+ for (var _i = 0; _i < arguments.length; _i++) {
164
+ args[_i] = arguments[_i];
165
+ }
166
+ warns.push(args);
167
+ },
168
+ debug: function () {
169
+ var args = [];
170
+ for (var _i = 0; _i < arguments.length; _i++) {
171
+ args[_i] = arguments[_i];
172
+ }
173
+ debugs.push(args);
174
+ }
175
+ };
176
+ }
177
+ //# sourceMappingURL=console.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.spec.js","sourceRoot":"","sources":["../ts/console.spec.ts"],"names":[],"mappings":";;AAAA,mDAAoD;AACpD,uCAGmB;AACnB,6CAAwC;AAExC,QAAQ,CAAC,mBAAmB,EAAE;IAC5B,EAAE,CAAC,+EAA+E,EAAE;QAClF,MAAM,CAAC,IAAA,0BAAe,EAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC3C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC7C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAE7C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC5C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC5C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAE5C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC5C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAE5C,MAAM,CAAC,IAAA,0BAAe,EAAC,GAAG,CAAC,CA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AAL;YAAM,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;YAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAAC,CAAC;KAC5C,CAAA;AACH,CAAC","sourcesContent":["import { createStandardLog } from './standardLog.js'\nimport {\n ConsoleLogFormatter, createConsoleLogReporter,\n LogFilter, logLevels, plainLogFormatter, toConsoleMethod\n} from './index.js'\nimport { polyfill } from './platform.js'\n\ndescribe('toConsoleMethod()', () => {\n it('converts any level to standard console method names: debug, info, warn, error', () => {\n expect(toConsoleMethod(1)).toEqual('error')\n expect(toConsoleMethod(399)).toEqual('error')\n expect(toConsoleMethod(400)).toEqual('error')\n\n expect(toConsoleMethod(401)).toEqual('warn')\n expect(toConsoleMethod(499)).toEqual('warn')\n expect(toConsoleMethod(500)).toEqual('warn')\n\n expect(toConsoleMethod(501)).toEqual('info')\n expect(toConsoleMethod(700)).toEqual('info')\n\n expect(toConsoleMethod(701)).toEqual('debug')\n expect(toConsoleMethod(800)).toEqual('debug')\n expect(toConsoleMethod(801)).toEqual('debug')\n expect(toConsoleMethod(Infinity)).toEqual('debug')\n })\n it('converts to debug for 0 (none) or negative (not valid) level', () => {\n // these are invalid input.\n // so instead of hiding them and not logged,\n // log them so that it is easier to discover.\n expect(toConsoleMethod(-1)).toEqual('debug')\n expect(toConsoleMethod(0)).toEqual('debug')\n })\n})\ndescribe('rendering tests', () => {\n test('plain rendering', () => {\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter });\n ['emergency', 'info', 'warn', 'debug'].forEach(level => {\n reporter.write({ id: 'plain', level: (logLevels as any)[level], args: ['hello', 'world'], timestamp: new Date() })\n })\n })\n})\n\n\ndescribe('createConsoleLogReporter', () => {\n let fakeConsole = createFakeConsole()\n beforeEach(() => polyfill.console = fakeConsole = createFakeConsole())\n\n describe('id', () => {\n test('default is \"console\"', () => {\n const reporter = createConsoleLogReporter()\n expect(reporter.id).toBe('console')\n })\n test('can be overridden', () => {\n const reporter = createConsoleLogReporter({ id: 'neo-console' })\n expect(reporter.id).toBe('neo-console')\n })\n })\n\n describe('log level', () => {\n test('error, alert, critical and emergency logs are written to console.error', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.critical, args: ['critical'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.alert, args: ['alert'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.error, args: ['error'], timestamp: new Date() })\n\n expect(fakeConsole.errors.length).toBe(4)\n })\n\n test('warn logs are written to console.warn', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.warn, args: ['warn'], timestamp: new Date() })\n\n expect(fakeConsole.warns.length).toBe(1)\n })\n\n test('notice and info logs are written to console.info', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.notice, args: ['notice'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.info, args: ['info'], timestamp: new Date() })\n\n expect(fakeConsole.infos.length).toBe(2)\n })\n\n\n test('debug, trace, and planck logs are written to console.debug', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n reporter.write({ id, level: logLevels.debug, args: ['debug'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.trace, args: ['trace'], timestamp: new Date() })\n reporter.write({ id, level: logLevels.planck, args: ['planck'], timestamp: new Date() })\n\n expect(fakeConsole.debugs.length).toBe(3)\n })\n })\n\n describe('custom logs', () => {\n test('are written according to their log level value', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter()\n\n const sl = createStandardLog({\n logLevel: logLevels.all,\n customLevels: {\n 'high': 50,\n 'important': 450,\n 'interest': 650,\n 'silly': 1000\n },\n reporters: [reporter]\n })\n const log = sl.getLogger([id])\n log.high('a')\n log.important('b')\n log.interest('c')\n log.silly('d')\n\n expect(fakeConsole.errors.length).toBe(1)\n expect(fakeConsole.warns.length).toBe(1)\n expect(fakeConsole.infos.length).toBe(1)\n expect(fakeConsole.debugs.length).toBe(1)\n })\n })\n\n const idFormatter: ConsoleLogFormatter = (entry) => [entry.id]\n\n describe('formatter', () => {\n test('use specific formatter', () => {\n const id = 'id-only'\n const reporter = createConsoleLogReporter({ formatter: idFormatter })\n expect(reporter.formatter).toBe(idFormatter)\n\n reporter.write({ id, level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['id-only']])\n })\n })\n\n describe('filter', () => {\n const filter: LogFilter = (entry) => entry.id !== 'secret'\n test('use specific filter', () => {\n const reporter = createConsoleLogReporter({ formatter: idFormatter, filter })\n expect(reporter.filter).toBe(filter)\n\n reporter.write({ id: 'normal', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n reporter.write({ id: 'secret', level: logLevels.emergency, args: ['emergency'], timestamp: new Date() })\n\n expect(fakeConsole.errors).toEqual([['normal']])\n })\n })\n\n test('write log entry with multiple arguments', () => {\n const id = 'log'\n const reporter = createConsoleLogReporter({ formatter: plainLogFormatter })\n\n const entry = { id, level: logLevels.info, args: ['a', 'b', 'c'], timestamp: new Date() }\n\n reporter.write(entry)\n\n expect(fakeConsole.infos).toEqual([\n [entry.timestamp.toISOString(), 'log', '(INFO)', 'a', 'b', 'c']\n ])\n })\n})\n\nfunction createFakeConsole() {\n const errors: any[] = []\n const infos: any[] = []\n const warns: any[] = []\n const debugs: any[] = []\n return {\n errors,\n infos,\n warns,\n debugs,\n error(...args: any[]) { errors.push(args) },\n info(...args: any[]) { infos.push(args) },\n warn(...args: any[]) { warns.push(args) },\n debug(...args: any[]) { debugs.push(args) }\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import { IsoError, ModuleError } from 'iso-error';
2
+ export declare class StandardLogError extends ModuleError {
3
+ constructor(description: string, options?: IsoError.Options);
4
+ }
5
+ export declare class InvalidId extends StandardLogError {
6
+ id: string;
7
+ constructor(id: string, options?: IsoError.Options);
8
+ }
9
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../ts/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEjD,qBAAa,gBAAiB,SAAQ,WAAW;gBACnC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO;CAG5D;AACD,qBAAa,SAAU,SAAQ,gBAAgB;IAC1B,EAAE,EAAE,MAAM;gBAAV,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO;CAG1D"}