@adviser/cement 0.2.27 → 0.2.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (319) hide show
  1. package/{base-sys-abstraction-C9WW3w57.d.cts → base-sys-abstraction-BkEiLHl0.d.ts} +8 -4
  2. package/{base-sys-abstraction-C9WW3w57.d.ts → base-sys-abstraction-Qj7pkY1N.d.cts} +8 -4
  3. package/{chunk-OXD3YZZ7.js → chunk-7KFVMTOS.js} +3 -47
  4. package/chunk-7KFVMTOS.js.map +1 -0
  5. package/{chunk-P5RXA4C4.js → chunk-GES3MUGV.js} +24 -27
  6. package/{chunk-LCPYQVWT.js.map → chunk-GES3MUGV.js.map} +1 -1
  7. package/{chunk-YDIUMYIE.js → chunk-Q65HLCNL.js} +8 -7
  8. package/chunk-Q65HLCNL.js.map +1 -0
  9. package/{chunk-DPIL5UIL.js → chunk-WMMUXBDX.js} +6 -2
  10. package/chunk-WMMUXBDX.js.map +1 -0
  11. package/{index-Dhb2fQiw.d.cts → index-Q3phXzYr.d.cts} +2 -21
  12. package/{index-CcsGcehs.d.ts → index-tIGZMHTc.d.ts} +2 -21
  13. package/index.cjs +265 -7343
  14. package/index.cjs.map +1 -1
  15. package/index.d.cts +73 -12
  16. package/index.d.ts +73 -12
  17. package/index.js +218 -7265
  18. package/index.js.map +1 -1
  19. package/node/index.cjs +220 -39
  20. package/node/index.cjs.map +1 -1
  21. package/node/index.d.cts +22 -4
  22. package/node/index.d.ts +22 -4
  23. package/node/index.js +201 -25
  24. package/node/index.js.map +1 -1
  25. package/package.json +23 -12
  26. package/src/LICENSE +201 -0
  27. package/src/README.md +39 -0
  28. package/src/base-sys-abstraction.test.ts +95 -0
  29. package/src/base-sys-abstraction.ts +242 -0
  30. package/src/bin2text.test.ts +59 -0
  31. package/src/bin2text.ts +47 -0
  32. package/src/crypto.test.ts +15 -0
  33. package/src/crypto.ts +125 -0
  34. package/src/file-service.ts +24 -0
  35. package/src/future.test.ts +32 -0
  36. package/src/future.ts +27 -0
  37. package/src/index.ts +22 -0
  38. package/src/jsr.json +20 -0
  39. package/src/log-level-impl.ts +87 -0
  40. package/src/log-writer-impl.ts +58 -0
  41. package/src/logger-impl.ts +498 -0
  42. package/src/logger.test.ts +1132 -0
  43. package/src/logger.ts +208 -0
  44. package/src/node/deno-file-service.ts +92 -0
  45. package/src/node/deno-sys-abstraction.ts +133 -0
  46. package/src/node/index.ts +4 -0
  47. package/src/node/mock-file-service.ts +45 -0
  48. package/src/node/node-file-service.ts +91 -0
  49. package/src/node/node-sys-abstraction.ts +121 -0
  50. package/src/option.ts +60 -0
  51. package/src/resolve-once.test.ts +321 -0
  52. package/src/resolve-once.ts +179 -0
  53. package/src/result.test.ts +102 -0
  54. package/src/result.ts +165 -0
  55. package/src/runtime.ts +36 -0
  56. package/src/sys-abstraction.ts +53 -0
  57. package/src/sys-env.test.ts +53 -0
  58. package/src/sys-env.ts +216 -0
  59. package/src/test/log-write-stream.ts +95 -0
  60. package/src/test/mock-logger.ts +40 -0
  61. package/src/time.ts +20 -0
  62. package/src/tracer.test.ts +314 -0
  63. package/src/tracer.ts +222 -0
  64. package/src/txt-en-decoder.ts +21 -0
  65. package/src/uri.test.ts +155 -0
  66. package/src/uri.ts +421 -0
  67. package/src/utils/console-write-stream.ts +72 -0
  68. package/src/utils/fanout-write-stream.ts +32 -0
  69. package/src/utils/index.ts +6 -0
  70. package/src/utils/rebuffer.ts +75 -0
  71. package/src/utils/stream-map.ts +67 -0
  72. package/src/utils/stream2string.ts +47 -0
  73. package/src/utils/string2stream.ts +14 -0
  74. package/src/version.ts +3 -0
  75. package/src/web/index.ts +1 -0
  76. package/src/web/web-sys-abstraction.ts +80 -0
  77. package/ts/base-sys-abstraction.d.ts +84 -0
  78. package/ts/base-sys-abstraction.d.ts.map +1 -0
  79. package/ts/base-sys-abstraction.js +178 -0
  80. package/ts/base-sys-abstraction.js.map +1 -0
  81. package/ts/base-sys-abstraction.test.d.ts +2 -0
  82. package/ts/base-sys-abstraction.test.d.ts.map +1 -0
  83. package/ts/base-sys-abstraction.test.js +82 -0
  84. package/ts/base-sys-abstraction.test.js.map +1 -0
  85. package/ts/bin2text.d.ts +3 -0
  86. package/ts/bin2text.d.ts.map +1 -0
  87. package/ts/bin2text.js +43 -0
  88. package/ts/bin2text.js.map +1 -0
  89. package/ts/bin2text.test.d.ts +2 -0
  90. package/ts/bin2text.test.d.ts.map +1 -0
  91. package/ts/bin2text.test.js +51 -0
  92. package/ts/bin2text.test.js.map +1 -0
  93. package/ts/crypto.d.ts +76 -0
  94. package/ts/crypto.d.ts.map +1 -0
  95. package/ts/crypto.js +22 -0
  96. package/ts/crypto.js.map +1 -0
  97. package/ts/crypto.test.d.ts +2 -0
  98. package/ts/crypto.test.d.ts.map +1 -0
  99. package/ts/crypto.test.js +14 -0
  100. package/ts/crypto.test.js.map +1 -0
  101. package/ts/file-service.d.ts +17 -0
  102. package/ts/file-service.d.ts.map +1 -0
  103. package/ts/file-service.js +2 -0
  104. package/ts/file-service.js.map +1 -0
  105. package/ts/future.d.ts +8 -0
  106. package/ts/future.d.ts.map +1 -0
  107. package/ts/future.js +38 -0
  108. package/ts/future.js.map +1 -0
  109. package/ts/future.test.d.ts +2 -0
  110. package/ts/future.test.d.ts.map +1 -0
  111. package/ts/future.test.js +28 -0
  112. package/ts/future.test.js.map +1 -0
  113. package/ts/index.d.ts +23 -0
  114. package/ts/index.d.ts.map +1 -0
  115. package/ts/index.js +23 -0
  116. package/ts/index.js.map +1 -0
  117. package/ts/log-level-impl.d.ts +14 -0
  118. package/ts/log-level-impl.d.ts.map +1 -0
  119. package/ts/log-level-impl.js +72 -0
  120. package/ts/log-level-impl.js.map +1 -0
  121. package/ts/log-writer-impl.d.ts +10 -0
  122. package/ts/log-writer-impl.d.ts.map +1 -0
  123. package/ts/log-writer-impl.js +45 -0
  124. package/ts/log-writer-impl.js.map +1 -0
  125. package/ts/logger-impl.d.ts +71 -0
  126. package/ts/logger-impl.d.ts.map +1 -0
  127. package/ts/logger-impl.js +412 -0
  128. package/ts/logger-impl.js.map +1 -0
  129. package/ts/logger.d.ts +84 -0
  130. package/ts/logger.d.ts.map +1 -0
  131. package/ts/logger.js +114 -0
  132. package/ts/logger.js.map +1 -0
  133. package/ts/logger.test.d.ts +2 -0
  134. package/ts/logger.test.d.ts.map +1 -0
  135. package/ts/logger.test.js +1023 -0
  136. package/ts/logger.test.js.map +1 -0
  137. package/ts/node/deno-file-service.d.ts +17 -0
  138. package/ts/node/deno-file-service.d.ts.map +1 -0
  139. package/ts/node/deno-file-service.js +65 -0
  140. package/ts/node/deno-file-service.js.map +1 -0
  141. package/ts/node/deno-sys-abstraction.d.ts +22 -0
  142. package/ts/node/deno-sys-abstraction.d.ts.map +1 -0
  143. package/ts/node/deno-sys-abstraction.js +101 -0
  144. package/ts/node/deno-sys-abstraction.js.map +1 -0
  145. package/ts/node/index.d.ts +5 -0
  146. package/ts/node/index.d.ts.map +1 -0
  147. package/ts/node/index.js +5 -0
  148. package/ts/node/index.js.map +1 -0
  149. package/ts/node/mock-file-service.d.ts +11 -0
  150. package/ts/node/mock-file-service.d.ts.map +1 -0
  151. package/ts/node/mock-file-service.js +34 -0
  152. package/ts/node/mock-file-service.js.map +1 -0
  153. package/ts/node/mock-file-service.test.d.ts +2 -0
  154. package/ts/node/mock-file-service.test.d.ts.map +1 -0
  155. package/ts/node/mock-file-service.test.js +31 -0
  156. package/ts/node/mock-file-service.test.js.map +1 -0
  157. package/ts/node/node-file-service.d.ts +16 -0
  158. package/ts/node/node-file-service.d.ts.map +1 -0
  159. package/ts/node/node-file-service.js +71 -0
  160. package/ts/node/node-file-service.js.map +1 -0
  161. package/ts/node/node-sys-abstraction.d.ts +22 -0
  162. package/ts/node/node-sys-abstraction.d.ts.map +1 -0
  163. package/ts/node/node-sys-abstraction.js +99 -0
  164. package/ts/node/node-sys-abstraction.js.map +1 -0
  165. package/ts/node/node-sys-abstraction.test.d.ts +2 -0
  166. package/ts/node/node-sys-abstraction.test.d.ts.map +1 -0
  167. package/ts/node/node-sys-abstraction.test.js +87 -0
  168. package/ts/node/node-sys-abstraction.test.js.map +1 -0
  169. package/ts/option.d.ts +25 -0
  170. package/ts/option.d.ts.map +1 -0
  171. package/ts/option.js +47 -0
  172. package/ts/option.js.map +1 -0
  173. package/ts/resolve-once.d.ts +46 -0
  174. package/ts/resolve-once.d.ts.map +1 -0
  175. package/ts/resolve-once.js +152 -0
  176. package/ts/resolve-once.js.map +1 -0
  177. package/ts/resolve-once.test.d.ts +2 -0
  178. package/ts/resolve-once.test.d.ts.map +1 -0
  179. package/ts/resolve-once.test.js +283 -0
  180. package/ts/resolve-once.test.js.map +1 -0
  181. package/ts/result.d.ts +34 -0
  182. package/ts/result.d.ts.map +1 -0
  183. package/ts/result.js +85 -0
  184. package/ts/result.js.map +1 -0
  185. package/ts/result.test.d.ts +2 -0
  186. package/ts/result.test.d.ts.map +1 -0
  187. package/ts/result.test.js +79 -0
  188. package/ts/result.test.js.map +1 -0
  189. package/ts/runtime.d.ts +8 -0
  190. package/ts/runtime.d.ts.map +1 -0
  191. package/ts/runtime.js +26 -0
  192. package/ts/runtime.js.map +1 -0
  193. package/ts/sys-abstraction.d.ts +36 -0
  194. package/ts/sys-abstraction.d.ts.map +1 -0
  195. package/ts/sys-abstraction.js +31 -0
  196. package/ts/sys-abstraction.js.map +1 -0
  197. package/ts/sys-env.d.ts +48 -0
  198. package/ts/sys-env.d.ts.map +1 -0
  199. package/ts/sys-env.js +176 -0
  200. package/ts/sys-env.js.map +1 -0
  201. package/ts/sys-env.test.d.ts +2 -0
  202. package/ts/sys-env.test.d.ts.map +1 -0
  203. package/ts/sys-env.test.js +51 -0
  204. package/ts/sys-env.test.js.map +1 -0
  205. package/ts/test/log-write-stream.d.ts +27 -0
  206. package/ts/test/log-write-stream.d.ts.map +1 -0
  207. package/ts/test/log-write-stream.js +74 -0
  208. package/ts/test/log-write-stream.js.map +1 -0
  209. package/ts/test/mock-logger.d.ts +14 -0
  210. package/ts/test/mock-logger.d.ts.map +1 -0
  211. package/ts/test/mock-logger.js +29 -0
  212. package/ts/test/mock-logger.js.map +1 -0
  213. package/ts/test/mock-logger.test.d.ts +2 -0
  214. package/ts/test/mock-logger.test.d.ts.map +1 -0
  215. package/ts/test/mock-logger.test.js +63 -0
  216. package/ts/test/mock-logger.test.js.map +1 -0
  217. package/ts/test/test-exit-handler.d.ts +2 -0
  218. package/ts/test/test-exit-handler.d.ts.map +1 -0
  219. package/ts/test/test-exit-handler.js +57 -0
  220. package/ts/test/test-exit-handler.js.map +1 -0
  221. package/ts/time.d.ts +13 -0
  222. package/ts/time.d.ts.map +1 -0
  223. package/ts/time.js +14 -0
  224. package/ts/time.js.map +1 -0
  225. package/ts/tracer.d.ts +59 -0
  226. package/ts/tracer.d.ts.map +1 -0
  227. package/ts/tracer.js +148 -0
  228. package/ts/tracer.js.map +1 -0
  229. package/ts/tracer.test.d.ts +2 -0
  230. package/ts/tracer.test.d.ts.map +1 -0
  231. package/ts/tracer.test.js +311 -0
  232. package/ts/tracer.test.js.map +1 -0
  233. package/ts/txt-en-decoder.d.ts +10 -0
  234. package/ts/txt-en-decoder.d.ts.map +1 -0
  235. package/ts/txt-en-decoder.js +15 -0
  236. package/ts/txt-en-decoder.js.map +1 -0
  237. package/ts/uri.d.ts +67 -0
  238. package/ts/uri.d.ts.map +1 -0
  239. package/ts/uri.js +283 -0
  240. package/ts/uri.js.map +1 -0
  241. package/ts/uri.test.d.ts +2 -0
  242. package/ts/uri.test.d.ts.map +1 -0
  243. package/ts/uri.test.js +119 -0
  244. package/ts/uri.test.js.map +1 -0
  245. package/ts/utils/console-write-stream.d.ts +21 -0
  246. package/ts/utils/console-write-stream.d.ts.map +1 -0
  247. package/ts/utils/console-write-stream.js +62 -0
  248. package/ts/utils/console-write-stream.js.map +1 -0
  249. package/ts/utils/fanout-write-stream.d.ts +12 -0
  250. package/ts/utils/fanout-write-stream.d.ts.map +1 -0
  251. package/ts/utils/fanout-write-stream.js +24 -0
  252. package/ts/utils/fanout-write-stream.js.map +1 -0
  253. package/ts/utils/index.d.ts +7 -0
  254. package/ts/utils/index.d.ts.map +1 -0
  255. package/ts/utils/index.js +7 -0
  256. package/ts/utils/index.js.map +1 -0
  257. package/ts/utils/rebuffer.d.ts +3 -0
  258. package/ts/utils/rebuffer.d.ts.map +1 -0
  259. package/ts/utils/rebuffer.js +60 -0
  260. package/ts/utils/rebuffer.js.map +1 -0
  261. package/ts/utils/rebuffer.test.d.ts +2 -0
  262. package/ts/utils/rebuffer.test.d.ts.map +1 -0
  263. package/ts/utils/rebuffer.test.js +77 -0
  264. package/ts/utils/rebuffer.test.js.map +1 -0
  265. package/ts/utils/stream-map.d.ts +9 -0
  266. package/ts/utils/stream-map.d.ts.map +1 -0
  267. package/ts/utils/stream-map.js +62 -0
  268. package/ts/utils/stream-map.js.map +1 -0
  269. package/ts/utils/stream-map.test.d.ts +2 -0
  270. package/ts/utils/stream-map.test.d.ts.map +1 -0
  271. package/ts/utils/stream-map.test.js +87 -0
  272. package/ts/utils/stream-map.test.js.map +1 -0
  273. package/ts/utils/stream-test-helper.d.ts +17 -0
  274. package/ts/utils/stream-test-helper.d.ts.map +1 -0
  275. package/ts/utils/stream-test-helper.js +37 -0
  276. package/ts/utils/stream-test-helper.js.map +1 -0
  277. package/ts/utils/stream2string.d.ts +3 -0
  278. package/ts/utils/stream2string.d.ts.map +1 -0
  279. package/ts/utils/stream2string.js +48 -0
  280. package/ts/utils/stream2string.js.map +1 -0
  281. package/ts/utils/stream2string.test.d.ts +2 -0
  282. package/ts/utils/stream2string.test.d.ts.map +1 -0
  283. package/ts/utils/stream2string.test.js +29 -0
  284. package/ts/utils/stream2string.test.js.map +1 -0
  285. package/ts/utils/string2stream.d.ts +4 -0
  286. package/ts/utils/string2stream.d.ts.map +1 -0
  287. package/ts/utils/string2stream.js +13 -0
  288. package/ts/utils/string2stream.js.map +1 -0
  289. package/ts/utils/string2stream.test.d.ts +2 -0
  290. package/ts/utils/string2stream.test.d.ts.map +1 -0
  291. package/ts/utils/string2stream.test.js +6 -0
  292. package/ts/utils/string2stream.test.js.map +1 -0
  293. package/ts/version.d.ts +2 -0
  294. package/ts/version.d.ts.map +1 -0
  295. package/ts/version.js +4 -0
  296. package/ts/version.js.map +1 -0
  297. package/ts/web/index.d.ts +2 -0
  298. package/ts/web/index.d.ts.map +1 -0
  299. package/ts/web/index.js +2 -0
  300. package/ts/web/index.js.map +1 -0
  301. package/ts/web/web-sys-abstraction.d.ts +4 -0
  302. package/ts/web/web-sys-abstraction.d.ts.map +1 -0
  303. package/ts/web/web-sys-abstraction.js +64 -0
  304. package/ts/web/web-sys-abstraction.js.map +1 -0
  305. package/utils/index.cjs +0 -42
  306. package/utils/index.cjs.map +1 -1
  307. package/utils/index.d.cts +1 -2
  308. package/utils/index.d.ts +1 -2
  309. package/utils/index.js +2 -7
  310. package/web/index.cjs +25 -7
  311. package/web/index.cjs.map +1 -1
  312. package/web/index.d.cts +2 -1
  313. package/web/index.d.ts +2 -1
  314. package/web/index.js +3 -3
  315. package/chunk-DPIL5UIL.js.map +0 -1
  316. package/chunk-LCPYQVWT.js +0 -21
  317. package/chunk-OXD3YZZ7.js.map +0 -1
  318. package/chunk-P5RXA4C4.js.map +0 -1
  319. package/chunk-YDIUMYIE.js.map +0 -1
@@ -0,0 +1,1023 @@
1
+ import { TimeFactory, IsLogger, Level, LevelHandlerImpl, LogCollector, LoggerImpl, logValue, Result, runtimeFn, TimeMode, BuildURI, URI, MutableURL, JSONFormatter, YAMLFormatter, } from "@adviser/cement";
2
+ import { WebSysAbstraction } from "@adviser/cement/web";
3
+ describe("TestLogger", () => {
4
+ let logCollector;
5
+ let logger;
6
+ beforeEach(() => {
7
+ logCollector = new LogCollector();
8
+ logger = new LoggerImpl({
9
+ out: logCollector,
10
+ sys: WebSysAbstraction({ TimeMode: TimeMode.STEP }),
11
+ levelHandler: new LevelHandlerImpl(),
12
+ });
13
+ });
14
+ describe("Error()", () => {
15
+ it("should set the level attribute to error", async () => {
16
+ logger.Error().Msg("");
17
+ await logger.Flush();
18
+ expect(logCollector.Logs()).toEqual([{ level: "error" }]);
19
+ });
20
+ it("should set the error message", async () => {
21
+ logger.Err(new Error("test")).Msg("");
22
+ await logger.Flush();
23
+ expect(logCollector.Logs()).toEqual([{ error: "test" }]);
24
+ });
25
+ it("should set the error from string", async () => {
26
+ logger.Err("test").Msg("");
27
+ await logger.Flush();
28
+ expect(logCollector.Logs()).toEqual([{ error: "test" }]);
29
+ });
30
+ it("should set the error from bool", async () => {
31
+ logger.Err(false).Msg("");
32
+ await logger.Flush();
33
+ expect(logCollector.Logs()).toEqual([{ error: "false" }]);
34
+ });
35
+ });
36
+ describe("Info()", () => {
37
+ it("should set the level attribute to info", async () => {
38
+ logger.Info().Msg("");
39
+ await logger.Flush();
40
+ expect(logCollector.Logs()).toEqual([{ level: "info" }]);
41
+ });
42
+ });
43
+ describe("Any()", () => {
44
+ it("should set the Any attribute", async () => {
45
+ logger.Any("key", "value").Msg("");
46
+ await logger.Flush();
47
+ expect(logCollector.Logs()).toEqual([{ key: "value" }]);
48
+ });
49
+ });
50
+ describe("Dur()", () => {
51
+ it("should set the Dur attribute", async () => {
52
+ logger.Dur("key", 123).Msg("");
53
+ await logger.Flush();
54
+ expect(logCollector.Logs()).toEqual([{ key: "123ms" }]);
55
+ });
56
+ });
57
+ describe("Uint64()", () => {
58
+ it("should set the Uint64 / number attribute", async () => {
59
+ logger.Uint64("Hey", 123).Msg("");
60
+ await logger.Flush();
61
+ expect(logCollector.Logs()).toEqual([{ Hey: 123 }]);
62
+ });
63
+ });
64
+ describe("Str()", () => {
65
+ it("should set the String attribute", async () => {
66
+ logger.Str("key", "value").Msg("");
67
+ await logger.Flush();
68
+ expect(logCollector.Logs()).toEqual([{ key: "value" }]);
69
+ });
70
+ });
71
+ describe("With()", () => {
72
+ it("should return a new logger with the same attributes", async () => {
73
+ const log = logger.With().Str("key", "value").Logger();
74
+ const newLogger = log.With().Str("str", "str").Logger();
75
+ logger.Msg("logger1");
76
+ logger.Msg("logger2");
77
+ newLogger.Msg("newLogger1");
78
+ newLogger.Msg("newLogger2");
79
+ log.Info().Msg("log1");
80
+ log.Info().Msg("log2");
81
+ await log.Flush();
82
+ expect(logCollector.Logs()).toEqual([
83
+ { msg: "logger1" },
84
+ { msg: "logger2" },
85
+ { key: "value", msg: "newLogger1", str: "str" },
86
+ { key: "value", msg: "newLogger2", str: "str" },
87
+ { level: "info", key: "value", msg: "log1" },
88
+ { level: "info", key: "value", msg: "log2" },
89
+ ]);
90
+ });
91
+ });
92
+ describe("Timestamp()", () => {
93
+ it("should set the Timestamp attribute", async () => {
94
+ const WithConstant = logger.With().Str("key", "withconstant").Str("key1", "anotherone").Logger();
95
+ const timelog = WithConstant.With().Timestamp().Str("key", "withconstant2").Logger();
96
+ timelog.Msg("1");
97
+ timelog.Msg("2");
98
+ timelog.Timestamp().Msg("3");
99
+ await timelog.Flush();
100
+ const timer = TimeFactory(TimeMode.STEP);
101
+ expect(logCollector.Logs()).toEqual([
102
+ {
103
+ key: "withconstant2",
104
+ key1: "anotherone",
105
+ ts: timer.Now().toISOString(),
106
+ msg: "1",
107
+ },
108
+ {
109
+ key: "withconstant2",
110
+ key1: "anotherone",
111
+ ts: timer.Now().toISOString(),
112
+ msg: "2",
113
+ },
114
+ {
115
+ key: "withconstant2",
116
+ key1: "anotherone",
117
+ ts: timer.Now().toISOString(),
118
+ msg: "3",
119
+ },
120
+ ]);
121
+ });
122
+ it("should NOT set the Timestamp attribute", async () => {
123
+ const timelog = logger.With().Logger();
124
+ timelog.Msg("1");
125
+ timelog.Msg("2");
126
+ timelog.Timestamp().Msg("3");
127
+ await timelog.Flush();
128
+ const timer = TimeFactory(TimeMode.STEP);
129
+ expect(logCollector.Logs()).toEqual([
130
+ { msg: "1" },
131
+ { msg: "2" },
132
+ {
133
+ ts: timer.Now().toISOString(),
134
+ msg: "3",
135
+ },
136
+ ]);
137
+ });
138
+ });
139
+ it("remove empty msg", async () => {
140
+ const log = logger;
141
+ log.Warn().Msg();
142
+ await log.Flush();
143
+ expect(logCollector.Logs()).toEqual([{ level: "warn" }]);
144
+ });
145
+ it("check log level", async () => {
146
+ const log = logger.With().Module("test").Logger().With().Logger();
147
+ log.Warn().Msg("Warn");
148
+ log.Info().Msg("Info");
149
+ log.Error().Msg("Error");
150
+ log.Log().Msg("Log");
151
+ log.WithLevel(Level.ERROR).Msg("WithLevel");
152
+ log.Debug().Str("should", "reset").Msg("Debug");
153
+ log.Info().Str("what", "the").Msg("Simple");
154
+ await log.Flush();
155
+ const expected = [
156
+ { msg: "Warn", level: "warn", module: "test" },
157
+ { msg: "Info", level: "info", module: "test" },
158
+ { msg: "Error", level: "error", module: "test" },
159
+ { msg: "Log", module: "test" },
160
+ { msg: "WithLevel", level: "error", module: "test" },
161
+ { level: "info", module: "test", msg: "Simple", what: "the" },
162
+ ];
163
+ expect(logCollector.Logs()).toEqual(expected);
164
+ logCollector.Logs().splice(0, logCollector.Logs().length);
165
+ logger.With().Logger().SetDebug("test");
166
+ log.Debug().Msg("Debug1");
167
+ await log.Flush();
168
+ expect(logCollector.Logs()).toEqual([...expected, { msg: "Debug1", level: "debug", module: "test" }]);
169
+ });
170
+ it("should flush all logs", async () => {
171
+ const log = new LoggerImpl();
172
+ log.Info().Msg("1");
173
+ log.Info().Msg("2");
174
+ await log.Flush();
175
+ log.Info().Msg("DONE");
176
+ return log.Flush();
177
+ });
178
+ it("carry debug", async () => {
179
+ const log = logger;
180
+ log.Module("xxx").SetDebug("yyy", ["i , xxx"]);
181
+ log.Debug().Msg("Debug1");
182
+ const next1 = log.With().Str("next1", "meno").Logger();
183
+ next1.Debug().Msg("Next1");
184
+ const next2 = next1.With().Str("next2", "meno").Logger();
185
+ next2.Debug().Msg("Next2");
186
+ next2.Module("zzz");
187
+ next2.Debug().Msg("Next3");
188
+ log.Debug().Msg("Top");
189
+ next1.Debug().Msg("Next1");
190
+ await log.Flush();
191
+ expect(logCollector.Logs()).toEqual([
192
+ {
193
+ level: "debug",
194
+ module: "xxx",
195
+ msg: "Debug1",
196
+ },
197
+ {
198
+ level: "debug",
199
+ module: "xxx",
200
+ msg: "Next1",
201
+ next1: "meno",
202
+ },
203
+ {
204
+ level: "debug",
205
+ module: "xxx",
206
+ msg: "Next2",
207
+ next1: "meno",
208
+ next2: "meno",
209
+ },
210
+ {
211
+ level: "debug",
212
+ module: "xxx",
213
+ msg: "Top",
214
+ },
215
+ {
216
+ level: "debug",
217
+ module: "xxx",
218
+ msg: "Next1",
219
+ next1: "meno",
220
+ },
221
+ ]);
222
+ });
223
+ it("should return an Error on Msg", async () => {
224
+ const log = logger;
225
+ log.Module("xxx").SetDebug("xxx");
226
+ log.Debug().Msg("Debug1");
227
+ expect(JSON.parse(log.Debug().Msg("Debug2").AsError().message)).toEqual({
228
+ level: "debug",
229
+ module: "xxx",
230
+ msg: "Debug2",
231
+ });
232
+ expect(JSON.parse(log.Info().Msg("Info2").AsError().message)).toEqual({
233
+ level: "info",
234
+ module: "xxx",
235
+ msg: "Info2",
236
+ });
237
+ await log.Flush();
238
+ expect(logCollector.Logs()).toEqual([
239
+ {
240
+ level: "debug",
241
+ module: "xxx",
242
+ msg: "Debug1",
243
+ },
244
+ {
245
+ level: "debug",
246
+ module: "xxx",
247
+ msg: "Debug2",
248
+ },
249
+ {
250
+ level: "info",
251
+ module: "xxx",
252
+ msg: "Info2",
253
+ },
254
+ ]);
255
+ });
256
+ it("top should enable modules wildcard", async () => {
257
+ const log = logger;
258
+ const xxxModule = log.With().Module("xxx").Logger();
259
+ log.Debug().Msg("log-Msg0");
260
+ xxxModule.Debug().Msg("xxx-log-Msg0");
261
+ log.EnableLevel(Level.DEBUG);
262
+ log.Debug().Msg("log-Msg");
263
+ xxxModule.Debug().Msg("xxx-log-Msg");
264
+ const yyyModule = log.With().Module("yyy").Logger();
265
+ yyyModule.Debug().Msg("yyy-log-Msg");
266
+ log.DisableLevel(Level.DEBUG);
267
+ yyyModule.Debug().Msg("yyy-log-Msg1");
268
+ log.Debug().Msg("log-Msg1");
269
+ xxxModule.Debug().Msg("xxx-log-Msg1");
270
+ await log.Flush();
271
+ expect(logCollector.Logs()).toEqual([
272
+ {
273
+ level: "debug",
274
+ msg: "log-Msg",
275
+ },
276
+ {
277
+ level: "debug",
278
+ module: "xxx",
279
+ msg: "xxx-log-Msg",
280
+ },
281
+ {
282
+ level: "debug",
283
+ module: "yyy",
284
+ msg: "yyy-log-Msg",
285
+ },
286
+ ]);
287
+ });
288
+ it("down should enable modules wildcard", async () => {
289
+ const log = logger;
290
+ const xxxModule = log.With().Module("xxx").Logger();
291
+ log.Debug().Msg("log-Msg");
292
+ xxxModule.Debug().Msg("xxx-log-Msg");
293
+ xxxModule.EnableLevel(Level.DEBUG);
294
+ log.Debug().Msg("log-Msg1");
295
+ xxxModule.Debug().Msg("xxx-log-Msg1");
296
+ const yyyModule = log.With().Module("yyy").Logger();
297
+ yyyModule.Debug().Msg("yyy-log-Msg");
298
+ yyyModule.DisableLevel(Level.DEBUG);
299
+ log.Debug().Msg("log-Msg2");
300
+ xxxModule.Debug().Msg("xxx-log-Msg2");
301
+ yyyModule.Debug().Msg("yyy-log-Msg2");
302
+ await log.Flush();
303
+ expect(logCollector.Logs()).toEqual([
304
+ {
305
+ level: "debug",
306
+ msg: "log-Msg1",
307
+ },
308
+ {
309
+ level: "debug",
310
+ module: "xxx",
311
+ msg: "xxx-log-Msg1",
312
+ },
313
+ {
314
+ level: "debug",
315
+ module: "yyy",
316
+ msg: "yyy-log-Msg",
317
+ },
318
+ ]);
319
+ });
320
+ it("global set debug on modules", async () => {
321
+ const log = logger;
322
+ const xxxModule = log.With().Module("xxx").Logger();
323
+ log.Debug().Msg("log-Msg");
324
+ xxxModule.Debug().Msg("xxx-log-Msg");
325
+ await log.Flush();
326
+ expect(logCollector.Logs()).toEqual([]);
327
+ xxxModule.EnableLevel(Level.DEBUG, "yyy", "xxx");
328
+ const yyyModule = log.With().Module("yyy").Logger();
329
+ yyyModule.Debug().Msg("yyy-log-Msg");
330
+ xxxModule.Debug().Msg("xxx-log-Msg1");
331
+ log.Debug().Msg("log-Msg1");
332
+ yyyModule.DisableLevel(Level.DEBUG, "yyy");
333
+ yyyModule.Debug().Msg("yyy-log-Msg1");
334
+ xxxModule.Debug().Msg("xxx-log-Msg2");
335
+ log.Debug().Msg("log-Msg3");
336
+ await log.Flush();
337
+ expect(logCollector.Logs()).toEqual([
338
+ {
339
+ level: "debug",
340
+ module: "yyy",
341
+ msg: "yyy-log-Msg",
342
+ },
343
+ {
344
+ level: "debug",
345
+ module: "xxx",
346
+ msg: "xxx-log-Msg1",
347
+ },
348
+ {
349
+ level: "debug",
350
+ module: "xxx",
351
+ msg: "xxx-log-Msg2",
352
+ },
353
+ ]);
354
+ });
355
+ it("global Check", () => {
356
+ const g1 = new LoggerImpl().EnableLevel(Level.DEBUG);
357
+ const g2 = new LoggerImpl();
358
+ const g3 = g2.With().Module("X").Logger();
359
+ expect(g1._levelHandler).toBe(g2._levelHandler);
360
+ expect(g1._levelHandler).toBe(g3._levelHandler);
361
+ expect(g1._levelHandler._globalLevels.has(Level.DEBUG)).toBeTruthy();
362
+ expect(g2._levelHandler._globalLevels.has(Level.DEBUG)).toBeTruthy();
363
+ expect(g3._levelHandler._globalLevels.has(Level.DEBUG)).toBeTruthy();
364
+ });
365
+ it("isLogger", () => {
366
+ const log = new LoggerImpl();
367
+ expect(IsLogger(log)).toBeTruthy();
368
+ expect(IsLogger({
369
+ Info: () => log.Info(),
370
+ Flush: () => log.Flush(),
371
+ With: () => log.With(),
372
+ })).toBeFalsy();
373
+ });
374
+ it("bool", async () => {
375
+ const log = logger;
376
+ log.Info().Bool("true", true).Msg("1");
377
+ log.Info().Bool("false", false).Msg("2");
378
+ log.Info().Bool("true", "wurst").Msg("3");
379
+ log.Info().Bool("false", null).Msg("4");
380
+ await log.Flush();
381
+ expect(logCollector.Logs()).toEqual([
382
+ {
383
+ level: "info",
384
+ msg: "1",
385
+ true: true,
386
+ },
387
+ {
388
+ false: false,
389
+ level: "info",
390
+ msg: "2",
391
+ },
392
+ {
393
+ level: "info",
394
+ msg: "3",
395
+ true: true,
396
+ },
397
+ {
398
+ false: false,
399
+ level: "info",
400
+ msg: "4",
401
+ },
402
+ ]);
403
+ });
404
+ it("int", async () => {
405
+ const log = logger;
406
+ log.Info().Int("1", 1).Msg("1");
407
+ log.Info().Int("2", 2).Msg("2");
408
+ log.Info().Int("3", 3).Msg("3");
409
+ log.Info().Int("4", 4).Msg("4");
410
+ await log.Flush();
411
+ expect(logCollector.Logs()).toEqual([
412
+ {
413
+ "1": 1,
414
+ level: "info",
415
+ msg: "1",
416
+ },
417
+ {
418
+ "2": 2,
419
+ level: "info",
420
+ msg: "2",
421
+ },
422
+ {
423
+ "3": 3,
424
+ level: "info",
425
+ msg: "3",
426
+ },
427
+ {
428
+ "4": 4,
429
+ level: "info",
430
+ msg: "4",
431
+ },
432
+ ]);
433
+ });
434
+ it("int", async () => {
435
+ const log = logger;
436
+ log.Info().Int("1", 1).Msg("1");
437
+ log.Info().Int("2", 2).Msg("2");
438
+ log.Info().Int("3", 3).Msg("3");
439
+ log.Info().Int("4", 4).Msg("4");
440
+ await log.Flush();
441
+ expect(logCollector.Logs()).toEqual([
442
+ {
443
+ "1": 1,
444
+ level: "info",
445
+ msg: "1",
446
+ },
447
+ {
448
+ "2": 2,
449
+ level: "info",
450
+ msg: "2",
451
+ },
452
+ {
453
+ "3": 3,
454
+ level: "info",
455
+ msg: "3",
456
+ },
457
+ {
458
+ "4": 4,
459
+ level: "info",
460
+ msg: "4",
461
+ },
462
+ ]);
463
+ });
464
+ it("ref", async () => {
465
+ const log = logger;
466
+ let value = 4711;
467
+ const fn = () => "" + value++;
468
+ log.Info().Ref("1", { toString: fn }).Msg("1");
469
+ log.Info().Ref("2", { toString: fn }).Msg("2");
470
+ log.Info().Ref("3", fn).Msg("3");
471
+ log.Info().Ref("4", fn).Msg("4");
472
+ await log.Flush();
473
+ expect(logCollector.Logs()).toEqual([
474
+ {
475
+ "1": "4711",
476
+ level: "info",
477
+ msg: "1",
478
+ },
479
+ {
480
+ "2": "4712",
481
+ level: "info",
482
+ msg: "2",
483
+ },
484
+ {
485
+ "3": "4713",
486
+ level: "info",
487
+ msg: "3",
488
+ },
489
+ {
490
+ "4": "4714",
491
+ level: "info",
492
+ msg: "4",
493
+ },
494
+ ]);
495
+ });
496
+ it("result", async () => {
497
+ const log = logger;
498
+ log.Info().Result("res.ok", Result.Ok(4711)).Msg("1");
499
+ log.Info().Result("res.err", Result.Err("Error")).Msg("2");
500
+ await log.Flush();
501
+ expect(logCollector.Logs()).toEqual([
502
+ {
503
+ level: "info",
504
+ msg: "1",
505
+ "res.ok": 4711,
506
+ },
507
+ {
508
+ error: "Error",
509
+ level: "info",
510
+ msg: "2",
511
+ },
512
+ ]);
513
+ });
514
+ it("url", async () => {
515
+ const log = logger;
516
+ const url = new MutableURL("http://localhost:8080");
517
+ log.Info().Url(url).Msg("1");
518
+ url.searchParams.set("test", "1");
519
+ log.Info().Url(url).Msg("2");
520
+ await log.Flush();
521
+ expect(logCollector.Logs()).toEqual([
522
+ {
523
+ level: "info",
524
+ msg: "1",
525
+ url: "http://localhost:8080/",
526
+ },
527
+ {
528
+ level: "info",
529
+ msg: "2",
530
+ url: "http://localhost:8080/?test=1",
531
+ },
532
+ ]);
533
+ });
534
+ it("str", async () => {
535
+ const log = logger;
536
+ log.Error().Str("1", undefined).Msg("1");
537
+ await log.Flush();
538
+ expect(logCollector.Logs()).toEqual([
539
+ {
540
+ "1": "--Falsy--",
541
+ level: "error",
542
+ msg: "1",
543
+ },
544
+ ]);
545
+ });
546
+ it("len", async () => {
547
+ const log = logger;
548
+ for (const key of [undefined, "key"]) {
549
+ log.Info().Len(undefined, key).Msg("undefined");
550
+ log.Info().Len(null, key).Msg("null");
551
+ log
552
+ .Info()
553
+ .Len(true, key)
554
+ .Msg("bool");
555
+ log
556
+ .Info()
557
+ .Len(1, key)
558
+ .Msg("number");
559
+ log.Info().Len("string", key).Msg("string");
560
+ log
561
+ .Info()
562
+ .Len(new Uint8Array([1, 2]), key)
563
+ .Msg("uint8array");
564
+ log
565
+ .Info()
566
+ .Len(Array.from([1, 2]), key)
567
+ .Msg("Array");
568
+ log.Info().Len({ a: 1 }, key).Msg("object");
569
+ }
570
+ await log.Flush();
571
+ expect(logCollector.Logs()).toEqual(Array.from(["len", "key"])
572
+ .map((key) => [
573
+ {
574
+ [key]: -1,
575
+ level: "info",
576
+ msg: "undefined",
577
+ },
578
+ {
579
+ [key]: -1,
580
+ level: "info",
581
+ msg: "null",
582
+ },
583
+ {
584
+ [key]: -1,
585
+ level: "info",
586
+ msg: "bool",
587
+ },
588
+ {
589
+ [key]: -1,
590
+ level: "info",
591
+ msg: "number",
592
+ },
593
+ {
594
+ [key]: 6,
595
+ level: "info",
596
+ msg: "string",
597
+ },
598
+ {
599
+ [key]: 2,
600
+ level: "info",
601
+ msg: "uint8array",
602
+ },
603
+ {
604
+ [key]: 2,
605
+ level: "info",
606
+ msg: "Array",
607
+ },
608
+ {
609
+ [key]: 1,
610
+ level: "info",
611
+ msg: "object",
612
+ },
613
+ ])
614
+ .flat());
615
+ });
616
+ it("wildcard debug", async () => {
617
+ const m1 = logger.With().Module("m1").Logger();
618
+ const m2 = logger.With().Module("m2").Logger();
619
+ m1.Debug().Msg("m1");
620
+ m2.Debug().Msg("m2");
621
+ logger.SetDebug("*");
622
+ m1.Debug().Msg("m3");
623
+ m2.Debug().Msg("m4");
624
+ await logger.Flush();
625
+ expect(logCollector.Logs()).toEqual([
626
+ {
627
+ level: "debug",
628
+ module: "m1",
629
+ msg: "m3",
630
+ },
631
+ {
632
+ level: "debug",
633
+ module: "m2",
634
+ msg: "m4",
635
+ },
636
+ ]);
637
+ });
638
+ it("array setDebug could receive anything", () => {
639
+ function c(u) {
640
+ return u;
641
+ }
642
+ logger.SetDebug(c(1), c(true), c(null), c(undefined), "", "test ", "test1, ,test2,,test3,,,more", [
643
+ c(2),
644
+ c(true),
645
+ c(null),
646
+ c(undefined),
647
+ "",
648
+ " testx",
649
+ "test1x , , test2x,, test3x ,,,morex",
650
+ ]);
651
+ expect(Array.from(logger._levelHandler._modules.keys())).toEqual([
652
+ "test",
653
+ "test1",
654
+ "test2",
655
+ "test3",
656
+ "more",
657
+ "testx",
658
+ "test1x",
659
+ "test2x",
660
+ "test3x",
661
+ "morex",
662
+ ]);
663
+ });
664
+ it("object setDebug could receive anything", async () => {
665
+ logger
666
+ .Error()
667
+ .Any("sock", {
668
+ m: 1,
669
+ nested: {
670
+ m: 2,
671
+ mfn: logValue(() => 23),
672
+ },
673
+ mfn: logValue(() => 19),
674
+ })
675
+ .Msg("1");
676
+ await logger.Flush();
677
+ expect(logCollector.Logs()).toEqual([
678
+ {
679
+ level: "error",
680
+ msg: "1",
681
+ sock: {
682
+ m: 1,
683
+ mfn: 19,
684
+ nested: {
685
+ m: 2,
686
+ mfn: 23,
687
+ },
688
+ },
689
+ },
690
+ ]);
691
+ });
692
+ it("don't serialize json on string", async () => {
693
+ logger
694
+ .Error()
695
+ .Err(new Error(JSON.stringify({ o: { h: 1 } })))
696
+ .Str("sock", JSON.stringify({ a: { h: 1 } }))
697
+ .Str("bla", '{a":1}')
698
+ .Msg("1");
699
+ await logger.Flush();
700
+ expect(logCollector.Logs()).toEqual([
701
+ {
702
+ level: "error",
703
+ error: { o: { h: 1 } },
704
+ msg: "1",
705
+ sock: { a: { h: 1 } },
706
+ bla: '{a":1}',
707
+ },
708
+ ]);
709
+ });
710
+ it("see exposed Stack", async () => {
711
+ var _a;
712
+ const e = new Error("test");
713
+ logger.Error().Err(e).Msg("1");
714
+ logger.SetExposeStack(true);
715
+ logger.Error().Err(e).Msg("2");
716
+ logger.SetExposeStack(false);
717
+ logger.Error().Err(e).Msg("3");
718
+ await logger.Flush();
719
+ expect(logCollector.Logs()).toEqual([
720
+ {
721
+ error: "test",
722
+ level: "error",
723
+ msg: "1",
724
+ },
725
+ {
726
+ error: "test",
727
+ level: "error",
728
+ msg: "2",
729
+ stack: (_a = e.stack) === null || _a === void 0 ? void 0 : _a.split("\n").map((s) => s.trim()),
730
+ },
731
+ {
732
+ error: "test",
733
+ level: "error",
734
+ msg: "3",
735
+ },
736
+ ]);
737
+ });
738
+ it("which writer for which runtime", async () => {
739
+ const logger = new LoggerImpl();
740
+ if (runtimeFn().isNodeIsh) {
741
+ expect(logger._logWriter._out instanceof WritableStream).toBeTruthy();
742
+ logger.Info().Msg("Running in Node");
743
+ }
744
+ if (runtimeFn().isBrowser) {
745
+ expect(logger._logWriter._out.constructor.name).toBe("ConsoleWriterStream");
746
+ logger.Info().Msg("Running in Browser");
747
+ }
748
+ });
749
+ it("self-ref", async () => {
750
+ const nested = {
751
+ m: 2,
752
+ mfn: logValue(() => 23),
753
+ };
754
+ nested.flat = nested;
755
+ nested.layer = {
756
+ jo: 4,
757
+ boom: nested,
758
+ };
759
+ logger
760
+ .Error()
761
+ .Any("sock", {
762
+ m: 1,
763
+ nested: nested,
764
+ mfn: logValue(() => 19),
765
+ })
766
+ .Msg("1");
767
+ await logger.Flush();
768
+ expect(logCollector.Logs()).toEqual([
769
+ {
770
+ level: "error",
771
+ msg: "1",
772
+ sock: {
773
+ m: 1,
774
+ mfn: 19,
775
+ nested: {
776
+ m: 2,
777
+ mfn: 23,
778
+ flat: "...",
779
+ layer: {
780
+ jo: 4,
781
+ boom: "...",
782
+ },
783
+ },
784
+ },
785
+ },
786
+ ]);
787
+ });
788
+ it("serialize json as string", async () => {
789
+ const suri = "file://./doof?test=1";
790
+ const auri = JSON.stringify({ uri: suri });
791
+ const buri = BuildURI.from(suri);
792
+ const uri = URI.from(suri);
793
+ expect(JSON.stringify({ uri: buri })).toEqual(auri);
794
+ expect(JSON.stringify({ uri })).toEqual(auri);
795
+ });
796
+ it("emits attributes", async () => {
797
+ const log = logger
798
+ .With()
799
+ .Str("str", "a str")
800
+ .Ref("bla", () => "blub")
801
+ .Any("what", { a: 1 })
802
+ .Logger();
803
+ expect(log.Attributes()).toEqual({ str: "a str", what: { a: 1 }, bla: "blub" });
804
+ const tlog = log.With().Timestamp().Logger();
805
+ const refTime = WebSysAbstraction({ TimeMode: TimeMode.STEP }).Time();
806
+ expect(tlog.Attributes()).toEqual({
807
+ str: "a str",
808
+ what: { a: 1 },
809
+ bla: "blub",
810
+ ts: refTime.Now().toISOString(),
811
+ });
812
+ });
813
+ it("Url could receive URL", async () => {
814
+ logger.Info().Url(new URL("http://localhost:8080")).Msg("1");
815
+ await logger.Flush();
816
+ expect(logCollector.Logs()).toEqual([
817
+ {
818
+ level: "info",
819
+ msg: "1",
820
+ url: "http://localhost:8080/",
821
+ },
822
+ ]);
823
+ });
824
+ it("Url could receive String", async () => {
825
+ logger.Info().Url("http://localhost:8080").Msg("1");
826
+ await logger.Flush();
827
+ expect(logCollector.Logs()).toEqual([
828
+ {
829
+ level: "info",
830
+ msg: "1",
831
+ url: "http://localhost:8080/",
832
+ },
833
+ ]);
834
+ });
835
+ it("error could receive Result", async () => {
836
+ logger.Info().Error().Err(Result.Err("xxxxx")).Msg("1");
837
+ logger.Info().Error().Err(Result.Ok("yyyyy")).Msg("2");
838
+ await logger.Flush();
839
+ expect(logCollector.Logs()).toEqual([
840
+ {
841
+ error: "xxxxx",
842
+ level: "error",
843
+ msg: "1",
844
+ },
845
+ {
846
+ noerror: "yyyyy",
847
+ level: "error",
848
+ msg: "2",
849
+ },
850
+ ]);
851
+ });
852
+ it("introspect json", async () => {
853
+ logger
854
+ .Info()
855
+ .Str("bla", JSON.stringify({ a: 4711 }))
856
+ .Any("y", {
857
+ a: JSON.stringify({ b: 4711, c: '{"d":4711}', e: ['{"f":4712}'] }),
858
+ })
859
+ .Msg(JSON.stringify(["x", 4712, { a: 4711 }, '{"d":4711}', '{"a":4711}']));
860
+ await logger.Flush();
861
+ expect(logCollector.Logs()).toEqual([
862
+ {
863
+ bla: { a: 4711 },
864
+ level: "info",
865
+ msg: [
866
+ "x",
867
+ 4712,
868
+ {
869
+ a: 4711,
870
+ },
871
+ {
872
+ d: 4711,
873
+ },
874
+ {
875
+ a: 4711,
876
+ },
877
+ ],
878
+ y: {
879
+ a: {
880
+ b: 4711,
881
+ c: {
882
+ d: 4711,
883
+ },
884
+ e: [
885
+ {
886
+ f: 4712,
887
+ },
888
+ ],
889
+ },
890
+ },
891
+ },
892
+ ]);
893
+ });
894
+ it("introspect uint8array", async () => {
895
+ logger
896
+ .Info()
897
+ .Any("fhex", new Uint8Array(new Array(36).fill(1).map((_, i) => i)))
898
+ .Any("hex", { a: new Uint8Array(new Array(36).fill(1).map((_, i) => i)) })
899
+ .Msg("1");
900
+ await logger.Flush();
901
+ expect(logCollector.Logs()).toEqual([
902
+ {
903
+ fhex: [
904
+ "0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................",
905
+ "0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................",
906
+ '0020 20 21 22 23 !"#',
907
+ ],
908
+ hex: {
909
+ a: [
910
+ "0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................",
911
+ "0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................",
912
+ '0020 20 21 22 23 !"#',
913
+ ],
914
+ },
915
+ level: "info",
916
+ msg: "1",
917
+ },
918
+ ]);
919
+ });
920
+ it("my own json formatter", async () => {
921
+ logger.SetExposeStack(true).SetFormatter(new JSONFormatter(logger.TxtEnDe(), 2));
922
+ logger
923
+ .Error()
924
+ .Str("bla", "blub")
925
+ .Str("xxx", '{"b": 4711}')
926
+ .Str("lines", "a\nb\nc")
927
+ .Any("flat", new Uint8Array(new Array(36).fill(1).map((_, i) => i)))
928
+ .Any("hi", {
929
+ ho: 1,
930
+ su: "bla",
931
+ js: '{"a":1}',
932
+ bi: new Uint8Array(new Array(36).fill(1).map((_, i) => i)),
933
+ ls: "a\nb\nc",
934
+ })
935
+ .Msg("hello");
936
+ await logger.Flush();
937
+ expect(logCollector.Logs(true)).toEqual([
938
+ "{",
939
+ ' "level": "error",',
940
+ ' "bla": "blub",',
941
+ ' "xxx": {',
942
+ ' "b": 4711',
943
+ " },",
944
+ ' "lines": [',
945
+ ' "a",',
946
+ ' "b",',
947
+ ' "c"',
948
+ " ],",
949
+ ' "flat": [',
950
+ ' "0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................",',
951
+ ' "0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................",',
952
+ ' "0020 20 21 22 23 !\\"#"',
953
+ " ],",
954
+ ' "hi": {',
955
+ ' "ho": 1,',
956
+ ' "su": "bla",',
957
+ ' "js": {',
958
+ ' "a": 1',
959
+ " },",
960
+ ' "bi": [',
961
+ ' "0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................",',
962
+ ' "0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................",',
963
+ ' "0020 20 21 22 23 !\\"#"',
964
+ " ],",
965
+ ' "ls": [',
966
+ ' "a",',
967
+ ' "b",',
968
+ ' "c"',
969
+ " ]",
970
+ " },",
971
+ ' "msg": "hello"',
972
+ "}",
973
+ ]);
974
+ });
975
+ it("my own yaml formatter", async () => {
976
+ const log = logger.SetExposeStack(true).SetFormatter(new YAMLFormatter(logger.TxtEnDe(), 2)).With().Logger();
977
+ log
978
+ .Error()
979
+ .Str("bla", "blub")
980
+ .Str("xxx", '{"b": 4711}')
981
+ .Str("lines", "a\nb\nc")
982
+ .Any("flat", new Uint8Array(new Array(36).fill(1).map((_, i) => i)))
983
+ .Any("hi", {
984
+ ho: 1,
985
+ su: "bla",
986
+ js: '{"a":1}',
987
+ bi: new Uint8Array(new Array(36).fill(1).map((_, i) => i)),
988
+ ls: "a\nb\nc",
989
+ })
990
+ .Msg("hello");
991
+ await log.Flush();
992
+ expect(logCollector.Logs(true)).toEqual([
993
+ "---",
994
+ "level: error",
995
+ "bla: blub",
996
+ "xxx:",
997
+ " b: 4711",
998
+ "lines:",
999
+ " - a",
1000
+ " - b",
1001
+ " - c",
1002
+ "flat:",
1003
+ " - 0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................",
1004
+ " - 0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................",
1005
+ ' - 0020 20 21 22 23 !"#',
1006
+ "hi:",
1007
+ " ho: 1",
1008
+ " su: bla",
1009
+ " js:",
1010
+ " a: 1",
1011
+ " bi:",
1012
+ " - 0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................",
1013
+ " - 0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................",
1014
+ ' - 0020 20 21 22 23 !"#',
1015
+ " ls:",
1016
+ " - a",
1017
+ " - b",
1018
+ " - c",
1019
+ "msg: hello",
1020
+ ]);
1021
+ });
1022
+ });
1023
+ //# sourceMappingURL=logger.test.js.map