@c9up/spectrum 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -7
- package/dist/Logger.d.ts +14 -4
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +83 -49
- package/dist/Logger.js.map +1 -1
- package/dist/LoggerManager.d.ts.map +1 -1
- package/dist/LoggerManager.js +7 -1
- package/dist/LoggerManager.js.map +1 -1
- package/dist/RustLogBridge.d.ts.map +1 -1
- package/dist/RustLogBridge.js +76 -16
- package/dist/RustLogBridge.js.map +1 -1
- package/dist/SpectrumProvider.d.ts +9 -1
- package/dist/SpectrumProvider.d.ts.map +1 -1
- package/dist/SpectrumProvider.js +53 -28
- package/dist/SpectrumProvider.js.map +1 -1
- package/dist/augmentations.d.ts +29 -0
- package/dist/augmentations.d.ts.map +1 -0
- package/dist/augmentations.js +18 -0
- package/dist/augmentations.js.map +1 -0
- package/dist/channels/FileChannel.d.ts +1 -1
- package/dist/channels/FileChannel.d.ts.map +1 -1
- package/dist/channels/FileChannel.js +39 -9
- package/dist/channels/FileChannel.js.map +1 -1
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +19 -7
- package/dist/configure.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/redact.d.ts +29 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +90 -0
- package/dist/redact.js.map +1 -0
- package/dist/services/main.d.ts +9 -0
- package/dist/services/main.d.ts.map +1 -1
- package/dist/services/main.js +11 -0
- package/dist/services/main.js.map +1 -1
- package/dist/targets.d.ts +6 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +59 -5
- package/dist/targets.js.map +1 -1
- package/dist/types.d.ts +38 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +33 -6
- package/dist/types.js.map +1 -1
- package/package.json +4 -2
- package/src/Logger.ts +113 -51
- package/src/LoggerManager.ts +9 -1
- package/src/RustLogBridge.ts +95 -20
- package/src/SpectrumProvider.ts +62 -32
- package/src/augmentations.ts +32 -0
- package/src/channels/FileChannel.ts +43 -9
- package/src/configure.ts +19 -7
- package/src/index.ts +4 -0
- package/src/redact.ts +100 -0
- package/src/services/main.ts +12 -0
- package/src/targets.ts +78 -12
- package/src/types.ts +60 -7
package/dist/SpectrumProvider.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
+
import "./augmentations.js";
|
|
1
2
|
import { ConsoleChannel } from "./channels/ConsoleChannel.js";
|
|
2
3
|
import { Logger } from "./Logger.js";
|
|
3
4
|
import { LoggerManager } from "./LoggerManager.js";
|
|
4
|
-
import { setLogger } from "./services/main.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
...Object.keys(LOG_LEVEL_ORDER),
|
|
8
|
-
"silent",
|
|
9
|
-
]);
|
|
10
|
-
function isValidLevel(raw) {
|
|
11
|
-
return typeof raw === "string" && VALID_LEVELS.has(raw);
|
|
12
|
-
}
|
|
13
|
-
function resolveLogLevel(raw) {
|
|
14
|
-
return isValidLevel(raw) ? raw : "info";
|
|
15
|
-
}
|
|
5
|
+
import { clearLogger, getLogger, setLogger } from "./services/main.js";
|
|
6
|
+
import { channelsFromTargets } from "./targets.js";
|
|
7
|
+
import { isLogLevelWithSilent, logLevel } from "./types.js";
|
|
16
8
|
/** A channel that owns a resource (e.g. a FileChannel WriteStream) to release on shutdown. */
|
|
17
9
|
function hasClose(ch) {
|
|
18
10
|
return "close" in ch && typeof ch.close === "function";
|
|
@@ -28,6 +20,8 @@ function isPartialLogConfig(value) {
|
|
|
28
20
|
}
|
|
29
21
|
export default class SpectrumProvider {
|
|
30
22
|
app;
|
|
23
|
+
/** The logger this provider bound, so shutdown only clears its own. */
|
|
24
|
+
#owned;
|
|
31
25
|
#channels = [];
|
|
32
26
|
constructor(app) {
|
|
33
27
|
this.app = app;
|
|
@@ -39,19 +33,38 @@ export default class SpectrumProvider {
|
|
|
39
33
|
this.#channels = Object.values(managerConfig.loggers).flatMap((logger) => logger.channels ?? []);
|
|
40
34
|
const manager = new LoggerManager(managerConfig);
|
|
41
35
|
this.app.container.singleton(Logger, () => manager);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
// Namespaced by the package that owns it, the way upstream namespaces
|
|
37
|
+
// `lucid.db`, `auth.manager` and `drive.manager` by theirs. The bare
|
|
38
|
+
// token stays bound beside it: it is what every existing
|
|
39
|
+
// `container.make(...)` asks for, and a token is not worth breaking an
|
|
40
|
+
// application over.
|
|
41
|
+
const logger = () => this.app.container.resolve(Logger);
|
|
42
|
+
this.app.container.singleton("spectrum.logger", logger);
|
|
43
|
+
this.app.container.singleton("logger", logger);
|
|
45
44
|
}
|
|
46
45
|
async boot() {
|
|
47
|
-
|
|
46
|
+
const logger = await this.app.container.resolve(Logger);
|
|
47
|
+
this.#owned = logger;
|
|
48
|
+
setLogger(logger);
|
|
48
49
|
}
|
|
49
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Release channel resources (e.g. FileChannel WriteStreams) on shutdown.
|
|
52
|
+
*
|
|
53
|
+
* AWAITED, and all of them: closing a file channel ends a stream, and ending
|
|
54
|
+
* one is a request rather than a completion. Firing them and returning let
|
|
55
|
+
* the shutdown run on to `process.exit` with the last lines still buffered.
|
|
56
|
+
* `allSettled` so one channel failing to close does not strand the others.
|
|
57
|
+
*/
|
|
50
58
|
async shutdown() {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
// Release the module-level singleton first, while it is still ours: past
|
|
60
|
+
// this point the channels are closing, and a logger reachable through
|
|
61
|
+
// `services/main` would be writing into streams that have ended.
|
|
62
|
+
if (this.#owned !== undefined && getLogger() === this.#owned)
|
|
63
|
+
clearLogger();
|
|
64
|
+
this.#owned = undefined;
|
|
65
|
+
await Promise.allSettled(this.#channels
|
|
66
|
+
.filter((channel) => hasClose(channel))
|
|
67
|
+
.map(async (channel) => channel.close()));
|
|
55
68
|
}
|
|
56
69
|
/**
|
|
57
70
|
* Normalize the raw `logger` config into a multi-logger config, filling in
|
|
@@ -76,15 +89,27 @@ export default class SpectrumProvider {
|
|
|
76
89
|
return { default: "app", loggers: { app: this.#normalizeLogger(flat) } };
|
|
77
90
|
}
|
|
78
91
|
#normalizeLogger(cfg) {
|
|
79
|
-
|
|
80
|
-
// only when none are supplied.
|
|
81
|
-
const channels = cfg.channels && cfg.channels.length > 0
|
|
82
|
-
? cfg.channels
|
|
83
|
-
: [new ConsoleChannel("pretty")];
|
|
84
|
-
const level = isValidLevel(cfg.level)
|
|
92
|
+
const level = isLogLevelWithSilent(cfg.level)
|
|
85
93
|
? cfg.level
|
|
86
|
-
:
|
|
94
|
+
: logLevel(process.env.LOG_LEVEL);
|
|
95
|
+
// An AdonisJS `config/logger.ts` declares its output as
|
|
96
|
+
// `transport.targets`, not as channels. It has to be converted HERE:
|
|
97
|
+
// filling `channels` in with the console fallback below is what stopped
|
|
98
|
+
// the Logger's own conversion from ever running (it only fires when
|
|
99
|
+
// `channels` is absent), so a config that declared a file target reached
|
|
100
|
+
// production writing to a console and nothing to the file it named.
|
|
101
|
+
const channels = this.#channelsFor(cfg, level);
|
|
87
102
|
return { ...cfg, level, channels };
|
|
88
103
|
}
|
|
104
|
+
/** Explicit channels, else the declared targets, else a pretty console. */
|
|
105
|
+
#channelsFor(cfg, level) {
|
|
106
|
+
if (cfg.channels && cfg.channels.length > 0)
|
|
107
|
+
return cfg.channels;
|
|
108
|
+
const declared = cfg.transport?.targets;
|
|
109
|
+
if (declared && declared.length > 0) {
|
|
110
|
+
return channelsFromTargets(declared, level);
|
|
111
|
+
}
|
|
112
|
+
return [new ConsoleChannel("pretty")];
|
|
113
|
+
}
|
|
89
114
|
}
|
|
90
115
|
//# sourceMappingURL=SpectrumProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpectrumProvider.js","sourceRoot":"","sources":["../src/SpectrumProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SpectrumProvider.js","sourceRoot":"","sources":["../src/SpectrumProvider.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAOnD,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5D,8FAA8F;AAC9F,SAAS,QAAQ,CAChB,EAAc;IAEd,OAAO,OAAO,IAAI,EAAE,IAAI,OAAO,EAAE,CAAC,KAAK,KAAK,UAAU,CAAC;AACxD,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACtC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,SAAS,IAAI,KAAK,CAClB,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC;AAgBD,MAAM,CAAC,OAAO,OAAO,gBAAgB;IAMd;IALtB,uEAAuE;IACvE,MAAM,CAAqB;IAE3B,SAAS,GAAiB,EAAE,CAAC;IAE7B,YAAsB,GAAuB;Q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AC1E,CAAC;IAED,gBAAgB,CAAC,GAAuB;QACvC,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC;YAC5C,CAAC,CAAC,GAAG,CAAC,KAAK;YACX,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACnC,wDAAwD;QACxD,qEAAqE;QACrE,wEAAwE;QACxE,oEAAoE;QACpE,yEAAyE;QACzE,oEAAoE;QACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IACpC,CAAC;IAED,2EAA2E;IAC3E,YAAY,CACX,GAAuB,EACvB,KAAyB;QAEzB,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,GAAG,CAAC,QAAQ,CAAC;QACjE,MAAM,QAAQ,GAAG,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC;QACxC,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrC,OAAO,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,CAAC,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvC,CAAC;CACD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Teach ream's `ContainerBindings` what `container.make('logger')` returns.
|
|
3
|
+
*
|
|
4
|
+
* ream declares that interface open on purpose: it registers its own entries
|
|
5
|
+
* and expects each package to contribute the one it owns — the comment on the
|
|
6
|
+
* interface names `logger` (spectrum) as exactly this. Nothing filled it in,
|
|
7
|
+
* so resolving by the string token answered `unknown` and every call site had
|
|
8
|
+
* to assert a type it could not prove.
|
|
9
|
+
*
|
|
10
|
+
* Loaded from the package barrel and from the provider, so registering
|
|
11
|
+
* spectrum is enough — an application writes no `declare module` of its own.
|
|
12
|
+
*
|
|
13
|
+
* Type-only, and ream stays an OPTIONAL peer: nothing here reaches a runtime
|
|
14
|
+
* import, and a `declare module` for a specifier that does not resolve is
|
|
15
|
+
* simply inert.
|
|
16
|
+
*/
|
|
17
|
+
import type { Logger } from "./Logger.js";
|
|
18
|
+
declare module "@c9up/ream/types" {
|
|
19
|
+
interface ContainerBindings {
|
|
20
|
+
/** The logger, bound by `SpectrumProvider`. */
|
|
21
|
+
"spectrum.logger": Logger;
|
|
22
|
+
/**
|
|
23
|
+
* The same binding under the name it had before the token carried its
|
|
24
|
+
* package. Kept bound so an existing `container.make(...)` resolves.
|
|
25
|
+
*/
|
|
26
|
+
logger: Logger;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=augmentations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"augmentations.d.ts","sourceRoot":"","sources":["../src/augmentations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,QAAQ,kBAAkB,CAAC;IACjC,UAAU,iBAAiB;QAC1B,+CAA+C;QAC/C,iBAAiB,EAAE,MAAM,CAAC;QAC1B;;;WAGG;QACH,MAAM,EAAE,MAAM,CAAC;KACf;CACD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Teach ream's `ContainerBindings` what `container.make('logger')` returns.
|
|
3
|
+
*
|
|
4
|
+
* ream declares that interface open on purpose: it registers its own entries
|
|
5
|
+
* and expects each package to contribute the one it owns — the comment on the
|
|
6
|
+
* interface names `logger` (spectrum) as exactly this. Nothing filled it in,
|
|
7
|
+
* so resolving by the string token answered `unknown` and every call site had
|
|
8
|
+
* to assert a type it could not prove.
|
|
9
|
+
*
|
|
10
|
+
* Loaded from the package barrel and from the provider, so registering
|
|
11
|
+
* spectrum is enough — an application writes no `declare module` of its own.
|
|
12
|
+
*
|
|
13
|
+
* Type-only, and ream stays an OPTIONAL peer: nothing here reaches a runtime
|
|
14
|
+
* import, and a `declare module` for a specifier that does not resolve is
|
|
15
|
+
* simply inert.
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=augmentations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"augmentations.js","sourceRoot":"","sources":["../src/augmentations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileChannel.d.ts","sourceRoot":"","sources":["../../src/channels/FileChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAY,YAAW,UAAU;;IAC7C,IAAI,SAAU;gBAkBF,MAAM,EAAE,iBAAiB;IAMrC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"FileChannel.d.ts","sourceRoot":"","sources":["../../src/channels/FileChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAY,YAAW,UAAU;;IAC7C,IAAI,SAAU;gBAkBF,MAAM,EAAE,iBAAiB;IAMrC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAmK5B;;;;;;;OAOG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA8C5B"}
|
|
@@ -62,7 +62,7 @@ export class FileChannel {
|
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
if (this.#
|
|
65
|
+
if (this.#needsRotation(bytes)) {
|
|
66
66
|
this.#pending.push(line);
|
|
67
67
|
this.#scheduleRotation();
|
|
68
68
|
return;
|
|
@@ -94,6 +94,22 @@ export class FileChannel {
|
|
|
94
94
|
process.stderr.write(`[Spectrum] FileChannel stream error: ${err.message}\n`);
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Whether this line has to wait for a rotation.
|
|
99
|
+
*
|
|
100
|
+
* The empty-file test is what stops an entry LARGER than `maxSizeBytes`
|
|
101
|
+
* from spinning forever: a fresh file starts at zero, so `0 + bytes > max`
|
|
102
|
+
* was still true and the line went back on the buffer, scheduled another
|
|
103
|
+
* rotation, and came back to the same answer — churning through a
|
|
104
|
+
* generation each time and never being written.
|
|
105
|
+
*
|
|
106
|
+
* A log line cannot be split, so an oversized one is written whole into a
|
|
107
|
+
* file of its own and the next line rotates. Bigger than the limit once
|
|
108
|
+
* beats absent.
|
|
109
|
+
*/
|
|
110
|
+
#needsRotation(bytes) {
|
|
111
|
+
return this.#currentSize > 0 && this.#currentSize + bytes > this.#maxSize;
|
|
112
|
+
}
|
|
97
113
|
#scheduleRotation() {
|
|
98
114
|
if (this.#rotating || this.#closed)
|
|
99
115
|
return;
|
|
@@ -110,14 +126,18 @@ export class FileChannel {
|
|
|
110
126
|
await this.#closeStream();
|
|
111
127
|
const oldest = `${this.#filePath}.${this.#maxFiles - 1}`;
|
|
112
128
|
await fsp.rm(oldest, { force: true });
|
|
129
|
+
// Shift the numbered generations up, oldest first: .1 → .2, .2 → .3…
|
|
130
|
+
//
|
|
131
|
+
// The i===1 pass used to take the LIVE file rather than `.1`, so `.1`
|
|
132
|
+
// was never written and the rename below found nothing left to move.
|
|
133
|
+
// With maxFiles=3 that kept one generation where two were configured,
|
|
134
|
+
// and every rotation destroyed the one before it.
|
|
113
135
|
for (let i = this.#maxFiles - 2; i >= 1; i--) {
|
|
114
|
-
const from = i === 1 ? this.#filePath : `${this.#filePath}.${i}`;
|
|
115
|
-
const to = `${this.#filePath}.${i + 1}`;
|
|
116
136
|
try {
|
|
117
|
-
await fsp.rename(
|
|
137
|
+
await fsp.rename(`${this.#filePath}.${i}`, `${this.#filePath}.${i + 1}`);
|
|
118
138
|
}
|
|
119
139
|
catch {
|
|
120
|
-
//
|
|
140
|
+
// That generation does not exist yet — skip
|
|
121
141
|
}
|
|
122
142
|
}
|
|
123
143
|
try {
|
|
@@ -146,7 +166,7 @@ export class FileChannel {
|
|
|
146
166
|
if (!line)
|
|
147
167
|
continue;
|
|
148
168
|
const bytes = Buffer.byteLength(line, "utf8");
|
|
149
|
-
if (this.#
|
|
169
|
+
if (this.#needsRotation(bytes)) {
|
|
150
170
|
this.#pending.unshift(line);
|
|
151
171
|
this.#scheduleRotation();
|
|
152
172
|
return;
|
|
@@ -172,16 +192,26 @@ export class FileChannel {
|
|
|
172
192
|
* the flag is set before the flush so nothing the flush triggers can reopen
|
|
173
193
|
* the file.
|
|
174
194
|
*/
|
|
175
|
-
close() {
|
|
195
|
+
async close() {
|
|
176
196
|
if (this.#closed)
|
|
177
197
|
return;
|
|
178
198
|
const pending = this.#pending.splice(0);
|
|
179
199
|
this.#closed = true;
|
|
180
200
|
if (this.#stream) {
|
|
201
|
+
const stream = this.#stream;
|
|
181
202
|
for (const line of pending)
|
|
182
|
-
|
|
183
|
-
this.#stream.end();
|
|
203
|
+
stream.write(line);
|
|
184
204
|
this.#stream = null;
|
|
205
|
+
// AWAIT the flush. `end()` asks the stream to finish; it does not
|
|
206
|
+
// finish it. Returning here let a shutdown run on to `process.exit`
|
|
207
|
+
// with the last lines still buffered — and the last lines are usually
|
|
208
|
+
// the ones explaining why the process is going down.
|
|
209
|
+
await new Promise((resolve) => {
|
|
210
|
+
stream.end(() => resolve());
|
|
211
|
+
// A stream that errors will never emit `finish`, and a shutdown
|
|
212
|
+
// must not hang on a full disk or a revoked permission.
|
|
213
|
+
stream.once("error", () => resolve());
|
|
214
|
+
});
|
|
185
215
|
return;
|
|
186
216
|
}
|
|
187
217
|
// No stream, because a rotation is in flight: it nulls the stream before
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileChannel.js","sourceRoot":"","sources":["../../src/channels/FileChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AACxC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AASlC,MAAM,OAAO,WAAW;IACvB,IAAI,GAAG,MAAM,CAAC;IACd,SAAS,CAAS;IAClB,QAAQ,CAAS;IACjB,SAAS,CAAS;IAClB,OAAO,GAA0B,IAAI,CAAC;IACtC,YAAY,GAAG,CAAC,CAAC;IACjB,SAAS,GAAG,KAAK,CAAC;IAClB,SAAS,GAAG,KAAK,CAAC;IAClB;;;;;;OAMG;IACH,OAAO,GAAG,KAAK,CAAC;IAChB,QAAQ,GAAa,EAAE,CAAC;IAExB,YAAY,MAAyB;QACpC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;QACxD,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,KAAe;QACpB,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,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EAAE,CAAC;gBACrB,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBAChE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACvB,CAAC;YACD,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACnD,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,CAAC,MAAM,CAAC,KAAK,CACnB,2BAA2B,KAAK,CAAC,MAAM,mCAAmC,IAAI,CAAC,SAAS,KAAK,CAC7F,CAAC;QACH,CAAC;IACF,CAAC;CACD"}
|
package/dist/configure.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACjB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,SAAS,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;CACjB;AAED,wBAAsB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAAA,UAAU,QAAQ;IACjB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,SAAS,CACR,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;CACjB;AAED,wBAAsB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA4BjE"}
|
package/dist/configure.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
export async function configure(codemods) {
|
|
2
2
|
await codemods.addProvider("@c9up/spectrum/provider");
|
|
3
|
-
await codemods.writeFile("config/logger.ts", `import {
|
|
3
|
+
await codemods.writeFile("config/logger.ts", `import { defineConfig, logLevel, targets } from '@c9up/spectrum'
|
|
4
|
+
|
|
5
|
+
const inProduction = process.env.NODE_ENV === 'production'
|
|
4
6
|
|
|
5
7
|
export default defineConfig({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
default: 'app',
|
|
9
|
+
loggers: {
|
|
10
|
+
app: {
|
|
11
|
+
enabled: true,
|
|
12
|
+
name: process.env.APP_NAME ?? 'app',
|
|
13
|
+
// LOG_LEVEL comes from outside the program, so it is checked rather than
|
|
14
|
+
// asserted: anything that is not a level reads as 'info'.
|
|
15
|
+
level: logLevel(process.env.LOG_LEVEL),
|
|
16
|
+
transport: {
|
|
17
|
+
targets: targets()
|
|
18
|
+
.pushIf(!inProduction, targets.pretty())
|
|
19
|
+
.pushIf(inProduction, targets.file({ destination: 1 }))
|
|
20
|
+
.toArray(),
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
12
24
|
})
|
|
13
25
|
`);
|
|
14
26
|
}
|
package/dist/configure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure.js","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,QAAkB;IACjD,MAAM,QAAQ,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC;IACtD,MAAM,QAAQ,CAAC,SAAS,CACvB,kBAAkB,EAClB
|
|
1
|
+
{"version":3,"file":"configure.js","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,QAAkB;IACjD,MAAM,QAAQ,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC;IACtD,MAAM,QAAQ,CAAC,SAAS,CACvB,kBAAkB,EAClB;;;;;;;;;;;;;;;;;;;;;;CAsBD,CACC,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @description Spectrum — structured logging for the Ream framework
|
|
4
4
|
* @implements FR54, FR55, FR56, FR57, FR58
|
|
5
5
|
*/
|
|
6
|
+
import "./augmentations.js";
|
|
6
7
|
export { ConsoleChannel } from "./channels/ConsoleChannel.js";
|
|
7
8
|
export { FileChannel } from "./channels/FileChannel.js";
|
|
8
9
|
export { defineConfig } from "./config.js";
|
|
@@ -12,5 +13,5 @@ export { LoggerManager } from "./LoggerManager.js";
|
|
|
12
13
|
export { createRustLogBridge, parseRustLog } from "./RustLogBridge.js";
|
|
13
14
|
export type { FileTargetOptions, PrettyTargetOptions, TransportTargetOptions, } from "./targets.js";
|
|
14
15
|
export { channelsFromTargets, Targets, targets } from "./targets.js";
|
|
15
|
-
export { type LogChannel, type LogConfig, type LogEntry, type LoggerManagerConfig, type LogLevelWithSilent, type LogSerializer, logEntryExtras, type RedactOptions, } from "./types.js";
|
|
16
|
+
export { isLogLevelWithSilent, type LogChannel, type LogConfig, type LogEntry, type LoggerManagerConfig, type LogLevelWithSilent, type LogSerializer, logEntryExtras, logLevel, type RedactOptions, } from "./types.js";
|
|
16
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EACX,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EACN,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,cAAc,EACd,KAAK,aAAa,GAClB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EACX,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EACN,oBAAoB,EACpB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,cAAc,EACd,QAAQ,EACR,KAAK,aAAa,GAClB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @description Spectrum — structured logging for the Ream framework
|
|
4
4
|
* @implements FR54, FR55, FR56, FR57, FR58
|
|
5
5
|
*/
|
|
6
|
+
import "./augmentations.js";
|
|
6
7
|
export { ConsoleChannel } from "./channels/ConsoleChannel.js";
|
|
7
8
|
export { FileChannel } from "./channels/FileChannel.js";
|
|
8
9
|
export { defineConfig } from "./config.js";
|
|
@@ -11,5 +12,5 @@ export { Logger } from "./Logger.js";
|
|
|
11
12
|
export { LoggerManager } from "./LoggerManager.js";
|
|
12
13
|
export { createRustLogBridge, parseRustLog } from "./RustLogBridge.js";
|
|
13
14
|
export { channelsFromTargets, Targets, targets } from "./targets.js";
|
|
14
|
-
export { logEntryExtras, } from "./types.js";
|
|
15
|
+
export { isLogLevelWithSilent, logEntryExtras, logLevel, } from "./types.js";
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMvE,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMvE,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EACN,oBAAoB,EAOpB,cAAc,EACd,QAAQ,GAER,MAAM,YAAY,CAAC"}
|
package/dist/redact.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction paths, in the syntax pino's `redact` option is written in.
|
|
3
|
+
*
|
|
4
|
+
* Upstream hands those paths to `fast-redact`, so a migrated `config/logger.ts`
|
|
5
|
+
* legitimately contains `req.headers.authorization`, `*.password`,
|
|
6
|
+
* `users[*].token` and `headers["set-cookie"]`. Understanding only the first of
|
|
7
|
+
* those — a literal dot-path — is not a smaller feature: it is a redaction that
|
|
8
|
+
* silently does nothing. The config says the password is censored, and the
|
|
9
|
+
* password is written out in full.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Split a redaction path into the keys it names.
|
|
13
|
+
*
|
|
14
|
+
* `a["b-c"]` and `a.b-c` name the same key: the brackets and the quotes are
|
|
15
|
+
* notation, not part of the name.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseRedactPath(path: string): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Replace everything `tokens` selects with `censor`, without touching the
|
|
20
|
+
* input.
|
|
21
|
+
*
|
|
22
|
+
* Copy-on-write, and the copy is only made once something actually matched —
|
|
23
|
+
* so an entry with no redacted field is passed through by reference, which is
|
|
24
|
+
* the common case on the hot path. The same rule is what keeps the walk
|
|
25
|
+
* honest: a path that names nothing leaves the object exactly as it was
|
|
26
|
+
* instead of inventing the key it was looking for.
|
|
27
|
+
*/
|
|
28
|
+
export declare function redactPath(node: unknown, tokens: readonly string[], censor: string, depth?: number): unknown;
|
|
29
|
+
//# sourceMappingURL=redact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAOtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACzB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,MAAM,EAAE,MAAM,EACd,KAAK,SAAI,GACP,OAAO,CAqBT"}
|
package/dist/redact.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction paths, in the syntax pino's `redact` option is written in.
|
|
3
|
+
*
|
|
4
|
+
* Upstream hands those paths to `fast-redact`, so a migrated `config/logger.ts`
|
|
5
|
+
* legitimately contains `req.headers.authorization`, `*.password`,
|
|
6
|
+
* `users[*].token` and `headers["set-cookie"]`. Understanding only the first of
|
|
7
|
+
* those — a literal dot-path — is not a smaller feature: it is a redaction that
|
|
8
|
+
* silently does nothing. The config says the password is censored, and the
|
|
9
|
+
* password is written out in full.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* fast-redact's own tokenizer: a run of characters that is not `.`, `[` or
|
|
13
|
+
* `]`, or anything between a pair of brackets.
|
|
14
|
+
*/
|
|
15
|
+
const PATH_TOKEN = /[^.[\]]+|\[(?:.)*?\]/g;
|
|
16
|
+
/**
|
|
17
|
+
* Split a redaction path into the keys it names.
|
|
18
|
+
*
|
|
19
|
+
* `a["b-c"]` and `a.b-c` name the same key: the brackets and the quotes are
|
|
20
|
+
* notation, not part of the name.
|
|
21
|
+
*/
|
|
22
|
+
export function parseRedactPath(path) {
|
|
23
|
+
const tokens = path.match(PATH_TOKEN);
|
|
24
|
+
if (!tokens)
|
|
25
|
+
return [];
|
|
26
|
+
return tokens.map((token) => {
|
|
27
|
+
const inner = token.startsWith("[") ? token.slice(1, -1) : token;
|
|
28
|
+
return inner.replace(/['"`]/g, "");
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Replace everything `tokens` selects with `censor`, without touching the
|
|
33
|
+
* input.
|
|
34
|
+
*
|
|
35
|
+
* Copy-on-write, and the copy is only made once something actually matched —
|
|
36
|
+
* so an entry with no redacted field is passed through by reference, which is
|
|
37
|
+
* the common case on the hot path. The same rule is what keeps the walk
|
|
38
|
+
* honest: a path that names nothing leaves the object exactly as it was
|
|
39
|
+
* instead of inventing the key it was looking for.
|
|
40
|
+
*/
|
|
41
|
+
export function redactPath(node, tokens, censor, depth = 0) {
|
|
42
|
+
const segment = tokens[depth];
|
|
43
|
+
if (segment === undefined || node === null || typeof node !== "object") {
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
const keys = selectKeys(node, segment);
|
|
47
|
+
if (keys.length === 0)
|
|
48
|
+
return node;
|
|
49
|
+
const isLast = depth === tokens.length - 1;
|
|
50
|
+
let copy = null;
|
|
51
|
+
for (const key of keys) {
|
|
52
|
+
const current = readKey(node, key);
|
|
53
|
+
const next = isLast
|
|
54
|
+
? censor
|
|
55
|
+
: redactPath(current, tokens, censor, depth + 1);
|
|
56
|
+
if (next === current)
|
|
57
|
+
continue;
|
|
58
|
+
if (!copy)
|
|
59
|
+
copy = Array.isArray(node) ? [...node] : { ...node };
|
|
60
|
+
writeKey(copy, key, next);
|
|
61
|
+
}
|
|
62
|
+
return copy ?? node;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The own keys a path segment selects.
|
|
66
|
+
*
|
|
67
|
+
* `*` takes every one of them — on an array too, whose own keys are its
|
|
68
|
+
* indices, which is what makes `users[*].token` reach into a list. Anything
|
|
69
|
+
* else takes that single key, and only if the object really has it: `in` would
|
|
70
|
+
* answer for `toString` and turn a redaction into an invented field.
|
|
71
|
+
*/
|
|
72
|
+
function selectKeys(node, segment) {
|
|
73
|
+
if (segment === "*")
|
|
74
|
+
return Object.keys(node);
|
|
75
|
+
return Object.hasOwn(node, segment) ? [segment] : [];
|
|
76
|
+
}
|
|
77
|
+
function readKey(node, key) {
|
|
78
|
+
const own = Object.getOwnPropertyDescriptor(node, key);
|
|
79
|
+
return own === undefined ? undefined : own.value;
|
|
80
|
+
}
|
|
81
|
+
function writeKey(node, key, value) {
|
|
82
|
+
if (Array.isArray(node)) {
|
|
83
|
+
const index = Number(key);
|
|
84
|
+
if (Number.isInteger(index))
|
|
85
|
+
node[index] = value;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
node[key] = value;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=redact.js.map
|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,CAAC;QAC1B,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;QACjD,OAAO;IACR,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACnB,CAAC"}
|
package/dist/services/main.d.ts
CHANGED
|
@@ -13,6 +13,15 @@ import type { Logger } from "../Logger.js";
|
|
|
13
13
|
export declare function setLogger(value: Logger): void;
|
|
14
14
|
/** @internal Read the singleton (or `undefined` pre-boot). */
|
|
15
15
|
export declare function getLogger(): Logger | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* @internal Release the singleton, so a shut-down application does not leave a
|
|
18
|
+
* dead logger reachable through `services/main`.
|
|
19
|
+
*
|
|
20
|
+
* The caller checks ownership first (`getLogger() === mine`): two applications
|
|
21
|
+
* share this module in one process, and the one shutting down must not clear
|
|
22
|
+
* what the other has since bound.
|
|
23
|
+
*/
|
|
24
|
+
export declare function clearLogger(): void;
|
|
16
25
|
declare const logger: Logger;
|
|
17
26
|
export default logger;
|
|
18
27
|
//# sourceMappingURL=main.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,iEAAiE;AACjE,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE7C;AAED,8DAA8D;AAC9D,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAE9C;AAED,QAAA,MAAM,MAAM,EAAE,MAWZ,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,iEAAiE;AACjE,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE7C;AAED,8DAA8D;AAC9D,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAE9C;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAED,QAAA,MAAM,MAAM,EAAE,MAWZ,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
package/dist/services/main.js
CHANGED
|
@@ -17,6 +17,17 @@ export function setLogger(value) {
|
|
|
17
17
|
export function getLogger() {
|
|
18
18
|
return instance;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @internal Release the singleton, so a shut-down application does not leave a
|
|
22
|
+
* dead logger reachable through `services/main`.
|
|
23
|
+
*
|
|
24
|
+
* The caller checks ownership first (`getLogger() === mine`): two applications
|
|
25
|
+
* share this module in one process, and the one shutting down must not clear
|
|
26
|
+
* what the other has since bound.
|
|
27
|
+
*/
|
|
28
|
+
export function clearLogger() {
|
|
29
|
+
instance = undefined;
|
|
30
|
+
}
|
|
20
31
|
const logger = new Proxy({}, {
|
|
21
32
|
get(_target, prop) {
|
|
22
33
|
if (!instance) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,IAAI,QAA4B,CAAC;AAEjC,iEAAiE;AACjE,MAAM,UAAU,SAAS,CAAC,KAAa;IACtC,QAAQ,GAAG,KAAK,CAAC;AAClB,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,SAAS;IACxB,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED,MAAM,MAAM,GAAW,IAAI,KAAK,CAAC,EAAY,EAAE;IAC9C,GAAG,CAAC,OAAO,EAAE,IAAI;QAChB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACd,2EAA2E;gBAC1E,6EAA6E,CAC9E,CAAC;QACH,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,CAAC;CACD,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/services/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,IAAI,QAA4B,CAAC;AAEjC,iEAAiE;AACjE,MAAM,UAAU,SAAS,CAAC,KAAa;IACtC,QAAQ,GAAG,KAAK,CAAC;AAClB,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,SAAS;IACxB,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW;IAC1B,QAAQ,GAAG,SAAS,CAAC;AACtB,CAAC;AAED,MAAM,MAAM,GAAW,IAAI,KAAK,CAAC,EAAY,EAAE;IAC9C,GAAG,CAAC,OAAO,EAAE,IAAI;QAChB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACd,2EAA2E;gBAC1E,6EAA6E,CAC9E,CAAC;QACH,CAAC;QACD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,CAAC;CACD,CAAC,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
package/dist/targets.d.ts
CHANGED
|
@@ -55,7 +55,12 @@ export declare const targets: (() => Targets) & {
|
|
|
55
55
|
* file when `destination` is a path, and to the console when it is a file
|
|
56
56
|
* descriptor, which is what `destination: 1` means in a containerised app that
|
|
57
57
|
* ships stdout to its log collector.
|
|
58
|
+
*
|
|
59
|
+
* A target with no level of its own inherits `inheritedLevel`, the level of the
|
|
60
|
+
* logger it belongs to — upstream's `defineConfig` fills the same gap, by
|
|
61
|
+
* writing the level into the target. Passing it instead of writing it leaves
|
|
62
|
+
* the caller's config object alone.
|
|
58
63
|
*/
|
|
59
|
-
export declare function channelsFromTargets(list: readonly TransportTargetOptions[]): LogChannel[];
|
|
64
|
+
export declare function channelsFromTargets(list: readonly TransportTargetOptions[], inheritedLevel?: LogLevelWithSilent | string): LogChannel[];
|
|
60
65
|
export {};
|
|
61
66
|
//# sourceMappingURL=targets.d.ts.map
|
package/dist/targets.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAY,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAO3E,+DAA+D;AAC/D,MAAM,WAAW,sBAAsB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAAC;CACpC;AAED,2EAA2E;AAC3E,MAAM,WAAW,iBAAiB;IACjC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;C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