@adviser/cement 0.2.28 → 0.2.29
Sign up to get free protection for your applications and to get access to all the features.
- package/{base-sys-abstraction-C9WW3w57.d.cts → base-sys-abstraction-BkEiLHl0.d.ts} +8 -4
- package/{base-sys-abstraction-C9WW3w57.d.ts → base-sys-abstraction-Qj7pkY1N.d.cts} +8 -4
- package/{chunk-OXD3YZZ7.js → chunk-7KFVMTOS.js} +3 -47
- package/chunk-7KFVMTOS.js.map +1 -0
- package/{chunk-P5RXA4C4.js → chunk-GES3MUGV.js} +24 -27
- package/{chunk-LCPYQVWT.js.map → chunk-GES3MUGV.js.map} +1 -1
- package/{chunk-YDIUMYIE.js → chunk-Q65HLCNL.js} +8 -7
- package/chunk-Q65HLCNL.js.map +1 -0
- package/{chunk-DPIL5UIL.js → chunk-WMMUXBDX.js} +6 -2
- package/chunk-WMMUXBDX.js.map +1 -0
- package/{index-Dhb2fQiw.d.cts → index-Q3phXzYr.d.cts} +2 -21
- package/{index-CcsGcehs.d.ts → index-tIGZMHTc.d.ts} +2 -21
- package/index.cjs +264 -7343
- package/index.cjs.map +1 -1
- package/index.d.cts +72 -12
- package/index.d.ts +72 -12
- package/index.js +217 -7265
- package/index.js.map +1 -1
- package/node/index.cjs +220 -39
- package/node/index.cjs.map +1 -1
- package/node/index.d.cts +22 -4
- package/node/index.d.ts +22 -4
- package/node/index.js +201 -25
- package/node/index.js.map +1 -1
- package/package.json +23 -12
- package/src/LICENSE +201 -0
- package/src/README.md +39 -0
- package/src/base-sys-abstraction.test.ts +95 -0
- package/src/base-sys-abstraction.ts +242 -0
- package/src/bin2text.test.ts +59 -0
- package/src/bin2text.ts +47 -0
- package/src/crypto.test.ts +15 -0
- package/src/crypto.ts +125 -0
- package/src/file-service.ts +24 -0
- package/src/future.test.ts +32 -0
- package/src/future.ts +27 -0
- package/src/index.ts +22 -0
- package/src/jsr.json +20 -0
- package/src/log-level-impl.ts +87 -0
- package/src/log-writer-impl.ts +58 -0
- package/src/logger-impl.ts +498 -0
- package/src/logger.test.ts +1132 -0
- package/src/logger.ts +208 -0
- package/src/node/deno-file-service.ts +92 -0
- package/src/node/deno-sys-abstraction.ts +133 -0
- package/src/node/index.ts +4 -0
- package/src/node/mock-file-service.ts +45 -0
- package/src/node/node-file-service.ts +91 -0
- package/src/node/node-sys-abstraction.ts +121 -0
- package/src/option.ts +60 -0
- package/src/resolve-once.test.ts +321 -0
- package/src/resolve-once.ts +179 -0
- package/src/result.test.ts +102 -0
- package/src/result.ts +165 -0
- package/src/runtime.ts +36 -0
- package/src/sys-abstraction.ts +53 -0
- package/src/sys-env.test.ts +53 -0
- package/src/sys-env.ts +216 -0
- package/src/test/log-write-stream.ts +95 -0
- package/src/test/mock-logger.ts +40 -0
- package/src/time.ts +20 -0
- package/src/tracer.test.ts +314 -0
- package/src/tracer.ts +222 -0
- package/src/txt-en-decoder.ts +21 -0
- package/src/uri.test.ts +155 -0
- package/src/uri.ts +421 -0
- package/src/utils/console-write-stream.ts +72 -0
- package/src/utils/fanout-write-stream.ts +32 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/rebuffer.ts +75 -0
- package/src/utils/stream-map.ts +67 -0
- package/src/utils/stream2string.ts +47 -0
- package/src/utils/string2stream.ts +14 -0
- package/src/version.ts +3 -0
- package/src/web/index.ts +1 -0
- package/src/web/web-sys-abstraction.ts +80 -0
- package/ts/base-sys-abstraction.d.ts +84 -0
- package/ts/base-sys-abstraction.d.ts.map +1 -0
- package/ts/base-sys-abstraction.js +178 -0
- package/ts/base-sys-abstraction.js.map +1 -0
- package/ts/base-sys-abstraction.test.d.ts +2 -0
- package/ts/base-sys-abstraction.test.d.ts.map +1 -0
- package/ts/base-sys-abstraction.test.js +82 -0
- package/ts/base-sys-abstraction.test.js.map +1 -0
- package/ts/bin2text.d.ts +3 -0
- package/ts/bin2text.d.ts.map +1 -0
- package/ts/bin2text.js +43 -0
- package/ts/bin2text.js.map +1 -0
- package/ts/bin2text.test.d.ts +2 -0
- package/ts/bin2text.test.d.ts.map +1 -0
- package/ts/bin2text.test.js +51 -0
- package/ts/bin2text.test.js.map +1 -0
- package/ts/crypto.d.ts +76 -0
- package/ts/crypto.d.ts.map +1 -0
- package/ts/crypto.js +22 -0
- package/ts/crypto.js.map +1 -0
- package/ts/crypto.test.d.ts +2 -0
- package/ts/crypto.test.d.ts.map +1 -0
- package/ts/crypto.test.js +14 -0
- package/ts/crypto.test.js.map +1 -0
- package/ts/file-service.d.ts +17 -0
- package/ts/file-service.d.ts.map +1 -0
- package/ts/file-service.js +2 -0
- package/ts/file-service.js.map +1 -0
- package/ts/future.d.ts +8 -0
- package/ts/future.d.ts.map +1 -0
- package/ts/future.js +38 -0
- package/ts/future.js.map +1 -0
- package/ts/future.test.d.ts +2 -0
- package/ts/future.test.d.ts.map +1 -0
- package/ts/future.test.js +28 -0
- package/ts/future.test.js.map +1 -0
- package/ts/index.d.ts +23 -0
- package/ts/index.d.ts.map +1 -0
- package/ts/index.js +23 -0
- package/ts/index.js.map +1 -0
- package/ts/log-level-impl.d.ts +14 -0
- package/ts/log-level-impl.d.ts.map +1 -0
- package/ts/log-level-impl.js +72 -0
- package/ts/log-level-impl.js.map +1 -0
- package/ts/log-writer-impl.d.ts +10 -0
- package/ts/log-writer-impl.d.ts.map +1 -0
- package/ts/log-writer-impl.js +45 -0
- package/ts/log-writer-impl.js.map +1 -0
- package/ts/logger-impl.d.ts +71 -0
- package/ts/logger-impl.d.ts.map +1 -0
- package/ts/logger-impl.js +412 -0
- package/ts/logger-impl.js.map +1 -0
- package/ts/logger.d.ts +84 -0
- package/ts/logger.d.ts.map +1 -0
- package/ts/logger.js +114 -0
- package/ts/logger.js.map +1 -0
- package/ts/logger.test.d.ts +2 -0
- package/ts/logger.test.d.ts.map +1 -0
- package/ts/logger.test.js +1023 -0
- package/ts/logger.test.js.map +1 -0
- package/ts/node/deno-file-service.d.ts +17 -0
- package/ts/node/deno-file-service.d.ts.map +1 -0
- package/ts/node/deno-file-service.js +65 -0
- package/ts/node/deno-file-service.js.map +1 -0
- package/ts/node/deno-sys-abstraction.d.ts +22 -0
- package/ts/node/deno-sys-abstraction.d.ts.map +1 -0
- package/ts/node/deno-sys-abstraction.js +101 -0
- package/ts/node/deno-sys-abstraction.js.map +1 -0
- package/ts/node/index.d.ts +5 -0
- package/ts/node/index.d.ts.map +1 -0
- package/ts/node/index.js +5 -0
- package/ts/node/index.js.map +1 -0
- package/ts/node/mock-file-service.d.ts +11 -0
- package/ts/node/mock-file-service.d.ts.map +1 -0
- package/ts/node/mock-file-service.js +34 -0
- package/ts/node/mock-file-service.js.map +1 -0
- package/ts/node/mock-file-service.test.d.ts +2 -0
- package/ts/node/mock-file-service.test.d.ts.map +1 -0
- package/ts/node/mock-file-service.test.js +31 -0
- package/ts/node/mock-file-service.test.js.map +1 -0
- package/ts/node/node-file-service.d.ts +16 -0
- package/ts/node/node-file-service.d.ts.map +1 -0
- package/ts/node/node-file-service.js +71 -0
- package/ts/node/node-file-service.js.map +1 -0
- package/ts/node/node-sys-abstraction.d.ts +22 -0
- package/ts/node/node-sys-abstraction.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.js +99 -0
- package/ts/node/node-sys-abstraction.js.map +1 -0
- package/ts/node/node-sys-abstraction.test.d.ts +2 -0
- package/ts/node/node-sys-abstraction.test.d.ts.map +1 -0
- package/ts/node/node-sys-abstraction.test.js +87 -0
- package/ts/node/node-sys-abstraction.test.js.map +1 -0
- package/ts/option.d.ts +25 -0
- package/ts/option.d.ts.map +1 -0
- package/ts/option.js +47 -0
- package/ts/option.js.map +1 -0
- package/ts/resolve-once.d.ts +46 -0
- package/ts/resolve-once.d.ts.map +1 -0
- package/ts/resolve-once.js +152 -0
- package/ts/resolve-once.js.map +1 -0
- package/ts/resolve-once.test.d.ts +2 -0
- package/ts/resolve-once.test.d.ts.map +1 -0
- package/ts/resolve-once.test.js +283 -0
- package/ts/resolve-once.test.js.map +1 -0
- package/ts/result.d.ts +34 -0
- package/ts/result.d.ts.map +1 -0
- package/ts/result.js +85 -0
- package/ts/result.js.map +1 -0
- package/ts/result.test.d.ts +2 -0
- package/ts/result.test.d.ts.map +1 -0
- package/ts/result.test.js +79 -0
- package/ts/result.test.js.map +1 -0
- package/ts/runtime.d.ts +8 -0
- package/ts/runtime.d.ts.map +1 -0
- package/ts/runtime.js +26 -0
- package/ts/runtime.js.map +1 -0
- package/ts/sys-abstraction.d.ts +36 -0
- package/ts/sys-abstraction.d.ts.map +1 -0
- package/ts/sys-abstraction.js +31 -0
- package/ts/sys-abstraction.js.map +1 -0
- package/ts/sys-env.d.ts +48 -0
- package/ts/sys-env.d.ts.map +1 -0
- package/ts/sys-env.js +176 -0
- package/ts/sys-env.js.map +1 -0
- package/ts/sys-env.test.d.ts +2 -0
- package/ts/sys-env.test.d.ts.map +1 -0
- package/ts/sys-env.test.js +51 -0
- package/ts/sys-env.test.js.map +1 -0
- package/ts/test/log-write-stream.d.ts +27 -0
- package/ts/test/log-write-stream.d.ts.map +1 -0
- package/ts/test/log-write-stream.js +74 -0
- package/ts/test/log-write-stream.js.map +1 -0
- package/ts/test/mock-logger.d.ts +14 -0
- package/ts/test/mock-logger.d.ts.map +1 -0
- package/ts/test/mock-logger.js +29 -0
- package/ts/test/mock-logger.js.map +1 -0
- package/ts/test/mock-logger.test.d.ts +2 -0
- package/ts/test/mock-logger.test.d.ts.map +1 -0
- package/ts/test/mock-logger.test.js +63 -0
- package/ts/test/mock-logger.test.js.map +1 -0
- package/ts/test/test-exit-handler.d.ts +2 -0
- package/ts/test/test-exit-handler.d.ts.map +1 -0
- package/ts/test/test-exit-handler.js +57 -0
- package/ts/test/test-exit-handler.js.map +1 -0
- package/ts/time.d.ts +13 -0
- package/ts/time.d.ts.map +1 -0
- package/ts/time.js +14 -0
- package/ts/time.js.map +1 -0
- package/ts/tracer.d.ts +59 -0
- package/ts/tracer.d.ts.map +1 -0
- package/ts/tracer.js +148 -0
- package/ts/tracer.js.map +1 -0
- package/ts/tracer.test.d.ts +2 -0
- package/ts/tracer.test.d.ts.map +1 -0
- package/ts/tracer.test.js +311 -0
- package/ts/tracer.test.js.map +1 -0
- package/ts/txt-en-decoder.d.ts +10 -0
- package/ts/txt-en-decoder.d.ts.map +1 -0
- package/ts/txt-en-decoder.js +15 -0
- package/ts/txt-en-decoder.js.map +1 -0
- package/ts/uri.d.ts +67 -0
- package/ts/uri.d.ts.map +1 -0
- package/ts/uri.js +283 -0
- package/ts/uri.js.map +1 -0
- package/ts/uri.test.d.ts +2 -0
- package/ts/uri.test.d.ts.map +1 -0
- package/ts/uri.test.js +119 -0
- package/ts/uri.test.js.map +1 -0
- package/ts/utils/console-write-stream.d.ts +21 -0
- package/ts/utils/console-write-stream.d.ts.map +1 -0
- package/ts/utils/console-write-stream.js +62 -0
- package/ts/utils/console-write-stream.js.map +1 -0
- package/ts/utils/fanout-write-stream.d.ts +12 -0
- package/ts/utils/fanout-write-stream.d.ts.map +1 -0
- package/ts/utils/fanout-write-stream.js +24 -0
- package/ts/utils/fanout-write-stream.js.map +1 -0
- package/ts/utils/index.d.ts +7 -0
- package/ts/utils/index.d.ts.map +1 -0
- package/ts/utils/index.js +7 -0
- package/ts/utils/index.js.map +1 -0
- package/ts/utils/rebuffer.d.ts +3 -0
- package/ts/utils/rebuffer.d.ts.map +1 -0
- package/ts/utils/rebuffer.js +60 -0
- package/ts/utils/rebuffer.js.map +1 -0
- package/ts/utils/rebuffer.test.d.ts +2 -0
- package/ts/utils/rebuffer.test.d.ts.map +1 -0
- package/ts/utils/rebuffer.test.js +77 -0
- package/ts/utils/rebuffer.test.js.map +1 -0
- package/ts/utils/stream-map.d.ts +9 -0
- package/ts/utils/stream-map.d.ts.map +1 -0
- package/ts/utils/stream-map.js +62 -0
- package/ts/utils/stream-map.js.map +1 -0
- package/ts/utils/stream-map.test.d.ts +2 -0
- package/ts/utils/stream-map.test.d.ts.map +1 -0
- package/ts/utils/stream-map.test.js +87 -0
- package/ts/utils/stream-map.test.js.map +1 -0
- package/ts/utils/stream-test-helper.d.ts +17 -0
- package/ts/utils/stream-test-helper.d.ts.map +1 -0
- package/ts/utils/stream-test-helper.js +37 -0
- package/ts/utils/stream-test-helper.js.map +1 -0
- package/ts/utils/stream2string.d.ts +3 -0
- package/ts/utils/stream2string.d.ts.map +1 -0
- package/ts/utils/stream2string.js +48 -0
- package/ts/utils/stream2string.js.map +1 -0
- package/ts/utils/stream2string.test.d.ts +2 -0
- package/ts/utils/stream2string.test.d.ts.map +1 -0
- package/ts/utils/stream2string.test.js +29 -0
- package/ts/utils/stream2string.test.js.map +1 -0
- package/ts/utils/string2stream.d.ts +4 -0
- package/ts/utils/string2stream.d.ts.map +1 -0
- package/ts/utils/string2stream.js +13 -0
- package/ts/utils/string2stream.js.map +1 -0
- package/ts/utils/string2stream.test.d.ts +2 -0
- package/ts/utils/string2stream.test.d.ts.map +1 -0
- package/ts/utils/string2stream.test.js +6 -0
- package/ts/utils/string2stream.test.js.map +1 -0
- package/ts/version.d.ts +2 -0
- package/ts/version.d.ts.map +1 -0
- package/ts/version.js +4 -0
- package/ts/version.js.map +1 -0
- package/ts/web/index.d.ts +2 -0
- package/ts/web/index.d.ts.map +1 -0
- package/ts/web/index.js +2 -0
- package/ts/web/index.js.map +1 -0
- package/ts/web/web-sys-abstraction.d.ts +4 -0
- package/ts/web/web-sys-abstraction.d.ts.map +1 -0
- package/ts/web/web-sys-abstraction.js +64 -0
- package/ts/web/web-sys-abstraction.js.map +1 -0
- package/utils/index.cjs +0 -42
- package/utils/index.cjs.map +1 -1
- package/utils/index.d.cts +1 -2
- package/utils/index.d.ts +1 -2
- package/utils/index.js +2 -7
- package/web/index.cjs +25 -7
- package/web/index.cjs.map +1 -1
- package/web/index.d.cts +2 -1
- package/web/index.d.ts +2 -1
- package/web/index.js +3 -3
- package/chunk-DPIL5UIL.js.map +0 -1
- package/chunk-LCPYQVWT.js +0 -21
- package/chunk-OXD3YZZ7.js.map +0 -1
- package/chunk-P5RXA4C4.js.map +0 -1
- package/chunk-YDIUMYIE.js.map +0 -1
@@ -0,0 +1,412 @@
|
|
1
|
+
import YAML from "yaml";
|
2
|
+
import { Level, logValue, removeSelfRef, asyncLogValue, } from "./logger.js";
|
3
|
+
import { WebSysAbstraction } from "./web/web-sys-abstraction.js";
|
4
|
+
import { Result } from "./result.js";
|
5
|
+
import { URI } from "./uri.js";
|
6
|
+
import { runtimeFn } from "./runtime.js";
|
7
|
+
import { ConsoleWriterStream } from "./utils/console-write-stream.js";
|
8
|
+
import { LogWriterStream } from "./log-writer-impl.js";
|
9
|
+
import { Utf8EnDecoderSingleton } from "./txt-en-decoder.js";
|
10
|
+
import { LevelHandlerSingleton } from "./log-level-impl.js";
|
11
|
+
function getLen(value) {
|
12
|
+
if (Array.isArray(value)) {
|
13
|
+
return logValue(() => value.length);
|
14
|
+
}
|
15
|
+
else if (typeof value === "string") {
|
16
|
+
return logValue(() => value.length);
|
17
|
+
}
|
18
|
+
else if (typeof value === "object" && value !== null) {
|
19
|
+
if (typeof value.size === "number") {
|
20
|
+
return logValue(() => value.size);
|
21
|
+
}
|
22
|
+
else if (typeof value.length === "number") {
|
23
|
+
return logValue(() => value.length);
|
24
|
+
}
|
25
|
+
return logValue(() => Object.keys(value).length);
|
26
|
+
}
|
27
|
+
return logValue(() => -1);
|
28
|
+
}
|
29
|
+
function hash(value) {
|
30
|
+
return "not implemented";
|
31
|
+
}
|
32
|
+
function toLogValue(lop) {
|
33
|
+
if (lop && typeof lop.then === "function") {
|
34
|
+
throw new Error("async logValue Not implemented");
|
35
|
+
}
|
36
|
+
return lop;
|
37
|
+
}
|
38
|
+
export class JSONFormatter {
|
39
|
+
constructor(txtEnde, space) {
|
40
|
+
this._txtEnDe = txtEnde;
|
41
|
+
this._space = space;
|
42
|
+
}
|
43
|
+
format(attr) {
|
44
|
+
return this._txtEnDe.encode(JSON.stringify(attr, removeSelfRef(), this._space) + "\n");
|
45
|
+
}
|
46
|
+
}
|
47
|
+
export class YAMLFormatter {
|
48
|
+
constructor(txtEnde, space) {
|
49
|
+
this._txtEnDe = txtEnde;
|
50
|
+
this._space = space;
|
51
|
+
}
|
52
|
+
format(attr) {
|
53
|
+
return this._txtEnDe.encode("---\n" + YAML.stringify(attr, removeSelfRef(), this._space) + "\n");
|
54
|
+
}
|
55
|
+
}
|
56
|
+
export class LoggerImpl {
|
57
|
+
constructor(params) {
|
58
|
+
this._attributes = {};
|
59
|
+
if (!params) {
|
60
|
+
params = {};
|
61
|
+
}
|
62
|
+
if (!params.sys) {
|
63
|
+
this._sys = WebSysAbstraction();
|
64
|
+
}
|
65
|
+
else {
|
66
|
+
this._sys = params.sys;
|
67
|
+
}
|
68
|
+
if (!params.txtEnDe) {
|
69
|
+
this._txtEnDe = Utf8EnDecoderSingleton();
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
this._txtEnDe = params.txtEnDe;
|
73
|
+
}
|
74
|
+
if (!params.formatter) {
|
75
|
+
this._formatter = new JSONFormatter(this._txtEnDe);
|
76
|
+
}
|
77
|
+
else {
|
78
|
+
this._formatter = params.formatter;
|
79
|
+
}
|
80
|
+
if (params.logWriter) {
|
81
|
+
this._logWriter = params.logWriter;
|
82
|
+
}
|
83
|
+
else {
|
84
|
+
if (!params.out) {
|
85
|
+
const rt = runtimeFn();
|
86
|
+
let stream;
|
87
|
+
if (rt.isBrowser) {
|
88
|
+
stream = new ConsoleWriterStream();
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
if (rt.isNodeIsh || rt.isReactNative || rt.isDeno) {
|
92
|
+
stream = this._sys.Stdout();
|
93
|
+
}
|
94
|
+
else {
|
95
|
+
throw new Error("No output defined for runtime");
|
96
|
+
}
|
97
|
+
}
|
98
|
+
this._logWriter = new LogWriterStream(stream);
|
99
|
+
}
|
100
|
+
else {
|
101
|
+
this._logWriter = new LogWriterStream(params.out);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
if (!params.withAttributes) {
|
105
|
+
this._withAttributes = {};
|
106
|
+
}
|
107
|
+
else {
|
108
|
+
this._withAttributes = Object.assign({}, params.withAttributes);
|
109
|
+
}
|
110
|
+
this._attributes = Object.assign({}, this._withAttributes);
|
111
|
+
if (params.levelHandler) {
|
112
|
+
this._levelHandler = params.levelHandler;
|
113
|
+
}
|
114
|
+
else {
|
115
|
+
this._levelHandler = LevelHandlerSingleton();
|
116
|
+
}
|
117
|
+
}
|
118
|
+
TxtEnDe() {
|
119
|
+
return this._txtEnDe;
|
120
|
+
}
|
121
|
+
Attributes() {
|
122
|
+
return JSON.parse(JSON.stringify(this._attributes, removeSelfRef()));
|
123
|
+
}
|
124
|
+
SetExposeStack(enable) {
|
125
|
+
this._levelHandler.setExposeStack(enable);
|
126
|
+
return this;
|
127
|
+
}
|
128
|
+
EnableLevel(level, ...modules) {
|
129
|
+
this._levelHandler.enableLevel(level, ...modules);
|
130
|
+
return this;
|
131
|
+
}
|
132
|
+
DisableLevel(level, ...modules) {
|
133
|
+
this._levelHandler.disableLevel(level, ...modules);
|
134
|
+
return this;
|
135
|
+
}
|
136
|
+
Module(key) {
|
137
|
+
this._attributes["module"] = logValue(key);
|
138
|
+
this._withAttributes["module"] = logValue(key);
|
139
|
+
return this;
|
140
|
+
}
|
141
|
+
SetDebug(...modules) {
|
142
|
+
this._levelHandler.setDebug(...modules);
|
143
|
+
return this;
|
144
|
+
}
|
145
|
+
SetFormatter(formatter) {
|
146
|
+
this._formatter = formatter;
|
147
|
+
return this;
|
148
|
+
}
|
149
|
+
Timestamp() {
|
150
|
+
this._attributes["ts"] = logValue(() => this._sys.Time().Now().toISOString());
|
151
|
+
return this;
|
152
|
+
}
|
153
|
+
Warn() {
|
154
|
+
this._attributes["level"] = logValue(Level.WARN);
|
155
|
+
return this;
|
156
|
+
}
|
157
|
+
Log() {
|
158
|
+
return this;
|
159
|
+
}
|
160
|
+
Debug() {
|
161
|
+
this._attributes["level"] = logValue(Level.DEBUG);
|
162
|
+
return this;
|
163
|
+
}
|
164
|
+
Error() {
|
165
|
+
this._attributes["level"] = logValue(Level.ERROR);
|
166
|
+
return this;
|
167
|
+
}
|
168
|
+
Info() {
|
169
|
+
this._attributes["level"] = logValue(Level.INFO);
|
170
|
+
return this;
|
171
|
+
}
|
172
|
+
Err(err) {
|
173
|
+
var _a;
|
174
|
+
if (Result.Is(err)) {
|
175
|
+
if (err.isOk()) {
|
176
|
+
this.Result("noerror", err);
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
this.Result("error", err);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
else if (err instanceof Error) {
|
183
|
+
this._attributes["error"] = logValue(err.message);
|
184
|
+
if (this._levelHandler.isStackExposed) {
|
185
|
+
this._attributes["stack"] = logValue((_a = err.stack) === null || _a === void 0 ? void 0 : _a.split("\n").map((s) => s.trim()));
|
186
|
+
}
|
187
|
+
}
|
188
|
+
else {
|
189
|
+
this._attributes["error"] = logValue("" + err);
|
190
|
+
}
|
191
|
+
return this;
|
192
|
+
}
|
193
|
+
WithLevel(l) {
|
194
|
+
this._attributes["level"] = logValue(l);
|
195
|
+
return this;
|
196
|
+
}
|
197
|
+
Ref(key, action) {
|
198
|
+
if (typeof action === "function") {
|
199
|
+
this._attributes[key] = logValue(action);
|
200
|
+
}
|
201
|
+
else if (typeof action.toString === "function") {
|
202
|
+
this._attributes[key] = logValue(() => action.toString());
|
203
|
+
}
|
204
|
+
else {
|
205
|
+
this._attributes[key] = logValue("INVALID REF");
|
206
|
+
}
|
207
|
+
return this;
|
208
|
+
}
|
209
|
+
Bool(key, value) {
|
210
|
+
this._attributes[key] = logValue(!!value);
|
211
|
+
return this;
|
212
|
+
}
|
213
|
+
Result(key, res) {
|
214
|
+
if (res.isOk()) {
|
215
|
+
this._attributes[key] = logValue(res.Ok());
|
216
|
+
}
|
217
|
+
else {
|
218
|
+
this.Err(res.Err());
|
219
|
+
}
|
220
|
+
return this;
|
221
|
+
}
|
222
|
+
Len(value, key = "len") {
|
223
|
+
this._attributes[key] = getLen(value);
|
224
|
+
return this;
|
225
|
+
}
|
226
|
+
Hash(value, key = "hash") {
|
227
|
+
this._attributes[key] = asyncLogValue(async () => `${getLen(value).value()}:${await hash(value)}`);
|
228
|
+
return this;
|
229
|
+
}
|
230
|
+
Url(url, key = "url") {
|
231
|
+
this.Ref(key, () => URI.from(url).toString());
|
232
|
+
return this;
|
233
|
+
}
|
234
|
+
Str(key, value) {
|
235
|
+
this._attributes[key] = logValue(value);
|
236
|
+
return this;
|
237
|
+
}
|
238
|
+
Any(key, value) {
|
239
|
+
this._attributes[key] = logValue(value);
|
240
|
+
return this;
|
241
|
+
}
|
242
|
+
Dur(key, nsec) {
|
243
|
+
this._attributes[key] = logValue(`${nsec}ms`);
|
244
|
+
return this;
|
245
|
+
}
|
246
|
+
Uint64(key, value) {
|
247
|
+
this._attributes[key] = logValue(value);
|
248
|
+
return this;
|
249
|
+
}
|
250
|
+
Int(key, value) {
|
251
|
+
return this.Uint64(key, value);
|
252
|
+
}
|
253
|
+
async Flush() {
|
254
|
+
return new Promise((resolve) => {
|
255
|
+
this._logWriter._flush(undefined, resolve);
|
256
|
+
});
|
257
|
+
}
|
258
|
+
With() {
|
259
|
+
return new WithLoggerBuilder(new LoggerImpl({
|
260
|
+
logWriter: this._logWriter,
|
261
|
+
sys: this._sys,
|
262
|
+
levelHandler: this._levelHandler,
|
263
|
+
formatter: this._formatter,
|
264
|
+
withAttributes: Object.assign({ module: this._attributes["module"] }, this._withAttributes),
|
265
|
+
}));
|
266
|
+
}
|
267
|
+
_resetAttributes(fn) {
|
268
|
+
const ret = fn();
|
269
|
+
Object.keys(this._attributes).forEach((key) => {
|
270
|
+
delete this._attributes[key];
|
271
|
+
});
|
272
|
+
Object.assign(this._attributes, this._withAttributes);
|
273
|
+
return ret;
|
274
|
+
}
|
275
|
+
Msg(...args) {
|
276
|
+
const fnError = this._resetAttributes(() => {
|
277
|
+
var _a, _b;
|
278
|
+
const doWrite = this._levelHandler.isEnabled((_a = toLogValue(this._attributes["level"])) === null || _a === void 0 ? void 0 : _a.value(), (_b = toLogValue(this._attributes["module"])) === null || _b === void 0 ? void 0 : _b.value());
|
279
|
+
this._attributes["msg"] = logValue(args.join(" "));
|
280
|
+
const msg = this._attributes["msg"].value();
|
281
|
+
if (typeof msg === "string" && !msg.trim().length) {
|
282
|
+
delete this._attributes["msg"];
|
283
|
+
}
|
284
|
+
let fnRet = () => this._formatter.format(Object.assign({}, this._attributes));
|
285
|
+
if (doWrite) {
|
286
|
+
const encoded = fnRet();
|
287
|
+
this._logWriter.write(encoded);
|
288
|
+
fnRet = () => encoded;
|
289
|
+
}
|
290
|
+
return fnRet;
|
291
|
+
});
|
292
|
+
return {
|
293
|
+
AsError: () => new Error(this._txtEnDe.decode(fnError())),
|
294
|
+
};
|
295
|
+
}
|
296
|
+
}
|
297
|
+
class WithLoggerBuilder {
|
298
|
+
constructor(li) {
|
299
|
+
this._li = li;
|
300
|
+
}
|
301
|
+
TxtEnDe() {
|
302
|
+
return this._li.TxtEnDe();
|
303
|
+
}
|
304
|
+
Logger() {
|
305
|
+
Object.assign(this._li._withAttributes, this._li._attributes);
|
306
|
+
return this._li;
|
307
|
+
}
|
308
|
+
Attributes() {
|
309
|
+
return Object.assign({}, this._li._attributes);
|
310
|
+
}
|
311
|
+
SetExposeStack(enable) {
|
312
|
+
this._li._levelHandler.setExposeStack(enable);
|
313
|
+
return this;
|
314
|
+
}
|
315
|
+
SetFormatter(fmt) {
|
316
|
+
this._li.SetFormatter(fmt);
|
317
|
+
return this;
|
318
|
+
}
|
319
|
+
EnableLevel(level, ...modules) {
|
320
|
+
this._li._levelHandler.enableLevel(level, ...modules);
|
321
|
+
return this;
|
322
|
+
}
|
323
|
+
DisableLevel(level, ...modules) {
|
324
|
+
this._li._levelHandler.enableLevel(level, ...modules);
|
325
|
+
return this;
|
326
|
+
}
|
327
|
+
Module(key) {
|
328
|
+
this._li.Module(key);
|
329
|
+
return this;
|
330
|
+
}
|
331
|
+
SetDebug(...modules) {
|
332
|
+
this._li.SetDebug(...modules);
|
333
|
+
return this;
|
334
|
+
}
|
335
|
+
Str(key, value) {
|
336
|
+
this._li.Str(key, value);
|
337
|
+
return this;
|
338
|
+
}
|
339
|
+
Len(value, key) {
|
340
|
+
this._li.Len(value, key);
|
341
|
+
return this;
|
342
|
+
}
|
343
|
+
Hash(value, key) {
|
344
|
+
this._li.Hash(value, key);
|
345
|
+
return this;
|
346
|
+
}
|
347
|
+
Ref(key, action) {
|
348
|
+
this._li.Ref(key, action);
|
349
|
+
return this;
|
350
|
+
}
|
351
|
+
Bool(key, value) {
|
352
|
+
this._li.Bool(key, value);
|
353
|
+
return this;
|
354
|
+
}
|
355
|
+
Result(key, res) {
|
356
|
+
this._li.Result(key, res);
|
357
|
+
return this;
|
358
|
+
}
|
359
|
+
Url(url, key) {
|
360
|
+
this._li.Url(url, key);
|
361
|
+
return this;
|
362
|
+
}
|
363
|
+
Int(key, value) {
|
364
|
+
this._li.Int(key, value);
|
365
|
+
return this;
|
366
|
+
}
|
367
|
+
Log() {
|
368
|
+
this._li.Log();
|
369
|
+
return this;
|
370
|
+
}
|
371
|
+
WithLevel(level) {
|
372
|
+
this._li.WithLevel(level);
|
373
|
+
return this;
|
374
|
+
}
|
375
|
+
Error() {
|
376
|
+
this._li.Error();
|
377
|
+
return this;
|
378
|
+
}
|
379
|
+
Warn() {
|
380
|
+
this._li.Error();
|
381
|
+
return this;
|
382
|
+
}
|
383
|
+
Debug() {
|
384
|
+
this._li.Debug();
|
385
|
+
return this;
|
386
|
+
}
|
387
|
+
Err(err) {
|
388
|
+
this._li.Err(err);
|
389
|
+
return this;
|
390
|
+
}
|
391
|
+
Info() {
|
392
|
+
this._li.Info();
|
393
|
+
return this;
|
394
|
+
}
|
395
|
+
Timestamp() {
|
396
|
+
this._li.Timestamp();
|
397
|
+
return this;
|
398
|
+
}
|
399
|
+
Any(key, value) {
|
400
|
+
this._li.Any(key, value);
|
401
|
+
return this;
|
402
|
+
}
|
403
|
+
Dur(key, nsec) {
|
404
|
+
this._li.Dur(key, nsec);
|
405
|
+
return this;
|
406
|
+
}
|
407
|
+
Uint64(key, value) {
|
408
|
+
this._li.Uint64(key, value);
|
409
|
+
return this;
|
410
|
+
}
|
411
|
+
}
|
412
|
+
//# sourceMappingURL=logger-impl.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"logger-impl.js","sourceRoot":"","sources":["../../src/logger-impl.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAIL,KAAK,EAEL,QAAQ,EAGR,aAAa,EAIb,aAAa,GAId,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAa,GAAG,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAgB,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACvD,IAAI,OAAQ,KAAe,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC9C,OAAO,QAAQ,CAAC,GAAG,EAAE,CAAE,KAAe,CAAC,IA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AO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,GAAY;QACd,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI;QACF,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,SAAS;QACP,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,GAAW,EAAE,KAAsB;QACrC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,GAAW,EAAE,IAAY;QAC3B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,CAAC,GAAW,EAAE,KAAa;QAC/B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/ts/logger.d.ts
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
import { Result } from "./result.js";
|
2
|
+
import { TxtEnDecoder } from "./txt-en-decoder.js";
|
3
|
+
import { CoerceURI } from "./uri.js";
|
4
|
+
export declare enum Level {
|
5
|
+
WARN = "warn",
|
6
|
+
DEBUG = "debug",
|
7
|
+
INFO = "info",
|
8
|
+
ERROR = "error"
|
9
|
+
}
|
10
|
+
export type Serialized = string | number | boolean;
|
11
|
+
export type FnSerialized = () => Serialized | Serialized[];
|
12
|
+
export declare class LogValue {
|
13
|
+
readonly fn: FnSerialized;
|
14
|
+
constructor(fn: FnSerialized);
|
15
|
+
value(): Serialized | Serialized[];
|
16
|
+
toJSON(): Serialized | Serialized[];
|
17
|
+
}
|
18
|
+
export type LogSerializable = Record<string, LogValue | Promise<LogValue>>;
|
19
|
+
export declare function removeSelfRef(lineEnd?: string): (key: unknown, val: unknown) => unknown;
|
20
|
+
export declare function asyncLogValue(val: () => Promise<Serialized>): Promise<LogValue>;
|
21
|
+
export type LogValueArg = LogValue | Serialized | Serialized[] | FnSerialized | undefined | null;
|
22
|
+
export declare function logValue(val: LogValueArg, state?: Set<unknown>): LogValue;
|
23
|
+
export interface Sized {
|
24
|
+
size: number;
|
25
|
+
}
|
26
|
+
export interface Lengthed {
|
27
|
+
length: number;
|
28
|
+
}
|
29
|
+
export type SizeOrLength = Sized | Lengthed;
|
30
|
+
export interface LogFormatter {
|
31
|
+
format(attr: LogSerializable): Uint8Array;
|
32
|
+
}
|
33
|
+
export interface LevelHandler {
|
34
|
+
enableLevel(level: Level, ...modules: string[]): void;
|
35
|
+
disableLevel(level: Level, ...modules: string[]): void;
|
36
|
+
setExposeStack(enable?: boolean): void;
|
37
|
+
isStackExposed: boolean;
|
38
|
+
setDebug(...modules: (string | string[])[]): void;
|
39
|
+
isEnabled(ilevel: unknown, module: unknown): boolean;
|
40
|
+
}
|
41
|
+
export interface LoggerInterface<R> {
|
42
|
+
TxtEnDe(): TxtEnDecoder;
|
43
|
+
Module(key: string): R;
|
44
|
+
EnableLevel(level: Level, ...modules: string[]): R;
|
45
|
+
DisableLevel(level: Level, ...modules: string[]): R;
|
46
|
+
Attributes(): Record<string, unknown>;
|
47
|
+
SetDebug(...modules: (string | string[])[]): R;
|
48
|
+
SetExposeStack(enable?: boolean): R;
|
49
|
+
SetFormatter(fmt: LogFormatter): R;
|
50
|
+
Ref(key: string, action: {
|
51
|
+
toString: () => string;
|
52
|
+
} | FnSerialized): R;
|
53
|
+
Result<T>(key: string, res: Result<T>): R;
|
54
|
+
Url(url: CoerceURI, key?: string): R;
|
55
|
+
Len(value: unknown, key?: string): R;
|
56
|
+
Hash(value: unknown, key?: string): R;
|
57
|
+
Str(key: string, value?: string): R;
|
58
|
+
Error(): R;
|
59
|
+
Warn(): R;
|
60
|
+
Debug(): R;
|
61
|
+
Log(): R;
|
62
|
+
WithLevel(level: Level): R;
|
63
|
+
Err(err: unknown | Result<unknown> | Error): R;
|
64
|
+
Info(): R;
|
65
|
+
Timestamp(): R;
|
66
|
+
Any(key: string, value: unknown): R;
|
67
|
+
Dur(key: string, nsec: number): R;
|
68
|
+
Uint64(key: string, value: number): R;
|
69
|
+
Int(key: string, value: number): R;
|
70
|
+
Bool(key: string, value: unknown): R;
|
71
|
+
}
|
72
|
+
export declare function IsLogger(obj: unknown): obj is Logger;
|
73
|
+
export interface WithLogger extends LoggerInterface<WithLogger> {
|
74
|
+
Logger(): Logger;
|
75
|
+
}
|
76
|
+
export interface AsError {
|
77
|
+
AsError(): Error;
|
78
|
+
}
|
79
|
+
export interface Logger extends LoggerInterface<Logger> {
|
80
|
+
With(): WithLogger;
|
81
|
+
Msg(...args: string[]): AsError;
|
82
|
+
Flush(): Promise<void>;
|
83
|
+
}
|
84
|
+
//# sourceMappingURL=logger.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,oBAAY,KAAK;IACf,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AACnD,MAAM,MAAM,YAAY,GAAG,MAAM,UAAU,GAAG,UAAU,EAAE,CAAC;AAE3D,qBAAa,QAAQ;IACP,QAAQ,CAAC,EAAE,EAAE,YAAY;gBAAhB,EAAE,EAAE,YAAY;IACrC,KAAK,IAAI,UAAU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 -0,0 +1,114 @@
|
|
1
|
+
import { bin2string } from "./bin2text.js";
|
2
|
+
export var Level;
|
3
|
+
(function (Level) {
|
4
|
+
Level["WARN"] = "warn";
|
5
|
+
Level["DEBUG"] = "debug";
|
6
|
+
Level["INFO"] = "info";
|
7
|
+
Level["ERROR"] = "error";
|
8
|
+
})(Level || (Level = {}));
|
9
|
+
export class LogValue {
|
10
|
+
constructor(fn) {
|
11
|
+
this.fn = fn;
|
12
|
+
}
|
13
|
+
value() {
|
14
|
+
return this.fn();
|
15
|
+
}
|
16
|
+
toJSON() {
|
17
|
+
return this.value();
|
18
|
+
}
|
19
|
+
}
|
20
|
+
export function removeSelfRef(lineEnd) {
|
21
|
+
const cache = new Set();
|
22
|
+
return function (key, value) {
|
23
|
+
if (typeof value === "object" && value !== null) {
|
24
|
+
if (cache.has(value))
|
25
|
+
return "...";
|
26
|
+
cache.add(value);
|
27
|
+
}
|
28
|
+
return lineEnd ? value + lineEnd : value;
|
29
|
+
};
|
30
|
+
}
|
31
|
+
export function asyncLogValue(val) {
|
32
|
+
throw new Error("Not implemented");
|
33
|
+
}
|
34
|
+
export function logValue(val, state = new Set([Math.random()])) {
|
35
|
+
switch (typeof val) {
|
36
|
+
case "function":
|
37
|
+
return new LogValue(val);
|
38
|
+
case "string": {
|
39
|
+
try {
|
40
|
+
const ret = JSON.parse(val);
|
41
|
+
if (typeof ret === "object" && ret !== null) {
|
42
|
+
return logValue(ret, state);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
catch (e) {
|
46
|
+
if (val.match(/[\n\r]/)) {
|
47
|
+
const lines = val.trimEnd().split(/[\n\r]/);
|
48
|
+
return new LogValue(() => lines);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
return new LogValue(() => val.toString());
|
52
|
+
}
|
53
|
+
case "number":
|
54
|
+
return new LogValue(() => val);
|
55
|
+
case "boolean":
|
56
|
+
return new LogValue(() => val);
|
57
|
+
case "object": {
|
58
|
+
if (ArrayBuffer.isView(val)) {
|
59
|
+
return logValue(bin2string(val, 512));
|
60
|
+
}
|
61
|
+
if (Array.isArray(val)) {
|
62
|
+
return new LogValue(() => val.map((v) => logValue(v).value()));
|
63
|
+
}
|
64
|
+
if (val === null) {
|
65
|
+
return new LogValue(() => "null");
|
66
|
+
}
|
67
|
+
if (state.has(val)) {
|
68
|
+
return new LogValue(() => "...");
|
69
|
+
}
|
70
|
+
state.add(val);
|
71
|
+
const res = {};
|
72
|
+
const typedVal = val;
|
73
|
+
for (const key in typedVal) {
|
74
|
+
const element = typedVal[key];
|
75
|
+
if (element instanceof LogValue) {
|
76
|
+
res[key] = element;
|
77
|
+
}
|
78
|
+
else {
|
79
|
+
res[key] = logValue(element, state);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
return new LogValue(() => res);
|
83
|
+
}
|
84
|
+
default:
|
85
|
+
if (!val) {
|
86
|
+
return new LogValue(() => "--Falsy--");
|
87
|
+
}
|
88
|
+
throw new Error(`Invalid type:${typeof val}`);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
export function IsLogger(obj) {
|
92
|
+
return (typeof obj === "object" &&
|
93
|
+
[
|
94
|
+
"Module",
|
95
|
+
"EnableLevel",
|
96
|
+
"DisableLevel",
|
97
|
+
"SetDebug",
|
98
|
+
"Str",
|
99
|
+
"Error",
|
100
|
+
"Warn",
|
101
|
+
"Debug",
|
102
|
+
"Log",
|
103
|
+
"WithLevel",
|
104
|
+
"Err",
|
105
|
+
"Info",
|
106
|
+
"Timestamp",
|
107
|
+
"Any",
|
108
|
+
"Dur",
|
109
|
+
"Uint64",
|
110
|
+
]
|
111
|
+
.map((fn) => typeof obj[fn] === "function")
|
112
|
+
.reduce((a, b) => a && b, true));
|
113
|
+
}
|
114
|
+
//# sourceMappingURL=logger.js.map
|
package/ts/logger.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,M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