@adviser/cement 0.0.0-jsr-t1

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