@c9up/spectrum 0.1.13 → 0.1.15
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/dist/SpectrumProvider.d.ts +8 -1
- package/dist/SpectrumProvider.d.ts.map +1 -1
- package/dist/SpectrumProvider.js +34 -6
- package/dist/SpectrumProvider.js.map +1 -1
- package/dist/channels/FileChannel.d.ts +1 -1
- package/dist/channels/FileChannel.d.ts.map +1 -1
- package/dist/channels/FileChannel.js +46 -7
- package/dist/channels/FileChannel.js.map +1 -1
- 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/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/SpectrumProvider.ts +44 -6
- package/src/channels/FileChannel.ts +50 -8
- package/src/services/main.ts +12 -0
- package/src/types.ts +10 -0
|
@@ -16,7 +16,14 @@ export default class SpectrumProvider {
|
|
|
16
16
|
constructor(app: SpectrumAppContext);
|
|
17
17
|
register(): void;
|
|
18
18
|
boot(): Promise<void>;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Release channel resources (e.g. FileChannel WriteStreams) on shutdown.
|
|
21
|
+
*
|
|
22
|
+
* AWAITED, and all of them: closing a file channel ends a stream, and ending
|
|
23
|
+
* one is a request rather than a completion. Firing them and returning let
|
|
24
|
+
* the shutdown run on to `process.exit` with the last lines still buffered.
|
|
25
|
+
* `allSettled` so one channel failing to close does not strand the others.
|
|
26
|
+
*/
|
|
20
27
|
shutdown(): Promise<void>;
|
|
21
28
|
}
|
|
22
29
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpectrumProvider.d.ts","sourceRoot":"","sources":["../src/SpectrumProvider.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"SpectrumProvider.d.ts","sourceRoot":"","sources":["../src/SpectrumProvider.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAkC5B,UAAU,iBAAiB;IAC1B,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI,CAAC;IACxD,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACjD;AAED,UAAU,mBAAmB;IAC5B,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;CAC7C;AAED,MAAM,WAAW,kBAAkB;IAClC,SAAS,EAAE,iBAAiB,CAAC;IAC7B,MAAM,EAAE,mBAAmB,CAAC;CAC5B;AAED,MAAM,CAAC,OAAO,OAAO,gBAAgB;;IAMxB,SAAS,CAAC,GAAG,EAAE,kBAAkB;gBAAvB,GAAG,EAAE,kBAAkB;IAE7C,QAAQ;IAsBF,IAAI;IAMV;;;;;;;OAOG;IACG,QAAQ;CAiFd"}
|
package/dist/SpectrumProvider.js
CHANGED
|
@@ -2,7 +2,7 @@ import "./augmentations.js";
|
|
|
2
2
|
import { ConsoleChannel } from "./channels/ConsoleChannel.js";
|
|
3
3
|
import { Logger } from "./Logger.js";
|
|
4
4
|
import { LoggerManager } from "./LoggerManager.js";
|
|
5
|
-
import { setLogger } from "./services/main.js";
|
|
5
|
+
import { clearLogger, getLogger, setLogger } from "./services/main.js";
|
|
6
6
|
import { channelsFromTargets } from "./targets.js";
|
|
7
7
|
import { isLogLevelWithSilent, logLevel } from "./types.js";
|
|
8
8
|
/** A channel that owns a resource (e.g. a FileChannel WriteStream) to release on shutdown. */
|
|
@@ -20,6 +20,8 @@ function isPartialLogConfig(value) {
|
|
|
20
20
|
}
|
|
21
21
|
export default class SpectrumProvider {
|
|
22
22
|
app;
|
|
23
|
+
/** The logger this provider bound, so shutdown only clears its own. */
|
|
24
|
+
#owned;
|
|
23
25
|
#channels = [];
|
|
24
26
|
constructor(app) {
|
|
25
27
|
this.app = app;
|
|
@@ -41,13 +43,39 @@ export default class SpectrumProvider {
|
|
|
41
43
|
this.app.container.singleton("logger", logger);
|
|
42
44
|
}
|
|
43
45
|
async boot() {
|
|
44
|
-
|
|
46
|
+
const logger = await this.app.container.resolve(Logger);
|
|
47
|
+
this.#owned = logger;
|
|
48
|
+
setLogger(logger);
|
|
45
49
|
}
|
|
46
|
-
/**
|
|
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
|
+
*/
|
|
47
58
|
async shutdown() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
const results = await Promise.allSettled(this.#channels
|
|
66
|
+
.filter((channel) => hasClose(channel))
|
|
67
|
+
.map(async (channel) => channel.close()));
|
|
68
|
+
// `allSettled` keeps one failure from stranding the others — that is why
|
|
69
|
+
// it is here — but the results were then thrown away. A channel that
|
|
70
|
+
// could not flush is lost log, and losing it silently during shutdown is
|
|
71
|
+
// how the lines explaining the shutdown disappear. Reported to stderr
|
|
72
|
+
// because the logger is exactly what has just been taken down.
|
|
73
|
+
const failures = results.filter((result) => result.status === "rejected");
|
|
74
|
+
for (const failure of failures) {
|
|
75
|
+
const reason = failure.reason instanceof Error
|
|
76
|
+
? failure.reason.message
|
|
77
|
+
: String(failure.reason);
|
|
78
|
+
process.stderr.write(`[spectrum] a channel failed to close; log written just before shutdown may be missing: ${reason}\n`);
|
|
51
79
|
}
|
|
52
80
|
}
|
|
53
81
|
/**
|
|
@@ -1 +1 @@
|
|
|
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,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
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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A2E;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"}
|
|
@@ -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;IAgL5B;;;;;;;OAOG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAiEtB"}
|
|
@@ -110,14 +110,26 @@ export class FileChannel {
|
|
|
110
110
|
#needsRotation(bytes) {
|
|
111
111
|
return this.#currentSize > 0 && this.#currentSize + bytes > this.#maxSize;
|
|
112
112
|
}
|
|
113
|
+
/** The rotation in flight, so `close()` can wait for it. */
|
|
114
|
+
#rotation = null;
|
|
113
115
|
#scheduleRotation() {
|
|
114
116
|
if (this.#rotating || this.#closed)
|
|
115
117
|
return;
|
|
116
118
|
this.#rotating = true;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
// The promise is KEPT, not just started. A rotation renames files and
|
|
120
|
+
// opens a new stream; `close()` arriving in the middle of that used to
|
|
121
|
+
// write the buffer to a stream the rotation was replacing and return,
|
|
122
|
+
// while the renames carried on behind it. The last lines — the ones
|
|
123
|
+
// explaining why the process is going down — could land in a file that
|
|
124
|
+
// was about to be moved, or in one nothing would look at.
|
|
125
|
+
this.#rotation = new Promise((resolve) => {
|
|
126
|
+
queueMicrotask(() => {
|
|
127
|
+
this.#rotate().finally(() => {
|
|
128
|
+
this.#rotating = false;
|
|
129
|
+
this.#flushPending();
|
|
130
|
+
this.#rotation = null;
|
|
131
|
+
resolve();
|
|
132
|
+
});
|
|
121
133
|
});
|
|
122
134
|
});
|
|
123
135
|
}
|
|
@@ -193,15 +205,42 @@ export class FileChannel {
|
|
|
193
205
|
* the file.
|
|
194
206
|
*/
|
|
195
207
|
close() {
|
|
208
|
+
// Every caller awaits the SAME completion — the promise itself, not a
|
|
209
|
+
// wrapper around it, which is why this is not `async`. Returning early on `#closed`
|
|
210
|
+
// meant a second `close()` resolved while the first was still flushing,
|
|
211
|
+
// so a shutdown that closed two channels in parallel — or simply called
|
|
212
|
+
// this twice — believed the last lines were on disk when they were still
|
|
213
|
+
// in the stream.
|
|
214
|
+
this.#closing ??= this.#close();
|
|
215
|
+
return this.#closing;
|
|
216
|
+
}
|
|
217
|
+
/** The single closing run, memoised by {@link close}. */
|
|
218
|
+
#closing;
|
|
219
|
+
async #close() {
|
|
196
220
|
if (this.#closed)
|
|
197
221
|
return;
|
|
198
|
-
|
|
222
|
+
// Closed FIRST, so nothing the rotation's flush triggers schedules
|
|
223
|
+
// another one, then wait for the rotation already in flight. Without
|
|
224
|
+
// this the two ran over each other and whichever finished last decided
|
|
225
|
+
// where the final lines were.
|
|
199
226
|
this.#closed = true;
|
|
227
|
+
await this.#rotation;
|
|
228
|
+
const pending = this.#pending.splice(0);
|
|
200
229
|
if (this.#stream) {
|
|
230
|
+
const stream = this.#stream;
|
|
201
231
|
for (const line of pending)
|
|
202
|
-
|
|
203
|
-
this.#stream.end();
|
|
232
|
+
stream.write(line);
|
|
204
233
|
this.#stream = null;
|
|
234
|
+
// AWAIT the flush. `end()` asks the stream to finish; it does not
|
|
235
|
+
// finish it. Returning here let a shutdown run on to `process.exit`
|
|
236
|
+
// with the last lines still buffered — and the last lines are usually
|
|
237
|
+
// the ones explaining why the process is going down.
|
|
238
|
+
await new Promise((resolve) => {
|
|
239
|
+
stream.end(() => resolve());
|
|
240
|
+
// A stream that errors will never emit `finish`, and a shutdown
|
|
241
|
+
// must not hang on a full disk or a revoked permission.
|
|
242
|
+
stream.once("error", () => resolve());
|
|
243
|
+
});
|
|
205
244
|
return;
|
|
206
245
|
}
|
|
207
246
|
// 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;AACx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IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YACvC,CAAC,CAAC,CAAC;YACH,OAAO;QACR,CAAC;QACD,yEAAyE;QACzE,yEAAyE;QACzE,qEAAqE;QACrE,qEAAqE;QACrE,EAAE;QACF,wEAAwE;QACxE,uEAAuE;QACvE,iBAAiB;QACjB,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,qEAAqE;IACrE,eAAe,CAAC,KAAe;QAC9B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAC/B,IAAI,CAAC;YACJ,IAAI,CAAC,IAAI,CAAC,SAAS,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/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/types.d.ts
CHANGED
|
@@ -52,6 +52,16 @@ export type { TransportTargetOptions } from "./targets.js";
|
|
|
52
52
|
export interface LogChannel {
|
|
53
53
|
name: string;
|
|
54
54
|
write(entry: LogEntry): void;
|
|
55
|
+
/**
|
|
56
|
+
* Release whatever the channel holds open, and finish writing.
|
|
57
|
+
*
|
|
58
|
+
* Allowed to be asynchronous, and that is the point: a file channel ends a
|
|
59
|
+
* stream, and ending one is a request, not a completion. Returning before
|
|
60
|
+
* the `finish` event meant a shutdown could reach `process.exit` with the
|
|
61
|
+
* last lines still in the kernel's hands — the lines about why the process
|
|
62
|
+
* was shutting down, most of the time.
|
|
63
|
+
*/
|
|
64
|
+
close?(): void | Promise<void>;
|
|
55
65
|
}
|
|
56
66
|
/** Transforms a value before it is written (pino `serializers` parity). */
|
|
57
67
|
export type LogSerializer = (value: unknown) => unknown;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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":["../src/types.ts"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAA6B;IACxD,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;CACT,CAAC;AAEF,mEAAmE;AACnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAEzD,uEAAuE;AACvE,MAAM,UAAU,cAAc,CAAC,KAAyB;IACvD,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS;IACzC,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC;IAC/B,QAAQ;CACR,CAAC,CAAC;AAEH,oDAAoD;AACpD,MAAM,UAAU,oBAAoB,CACnC,KAAc;IAEd,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACvB,GAAY,EACZ,WAA+B,MAAM;IAErC,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;AACnD,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAA6B;IACxD,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,EAAE;IACT,KAAK,EAAE,EAAE;CACT,CAAC;AAEF,mEAAmE;AACnE,M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
|
|
|
2
2
|
import { ConsoleChannel } from "./channels/ConsoleChannel.js";
|
|
3
3
|
import { Logger } from "./Logger.js";
|
|
4
4
|
import { LoggerManager } from "./LoggerManager.js";
|
|
5
|
-
import { setLogger } from "./services/main.js";
|
|
5
|
+
import { clearLogger, getLogger, setLogger } from "./services/main.js";
|
|
6
6
|
import { channelsFromTargets } from "./targets.js";
|
|
7
7
|
import type {
|
|
8
8
|
LogChannel,
|
|
@@ -13,7 +13,9 @@ import type {
|
|
|
13
13
|
import { isLogLevelWithSilent, logLevel } from "./types.js";
|
|
14
14
|
|
|
15
15
|
/** A channel that owns a resource (e.g. a FileChannel WriteStream) to release on shutdown. */
|
|
16
|
-
function hasClose(
|
|
16
|
+
function hasClose(
|
|
17
|
+
ch: LogChannel,
|
|
18
|
+
): ch is LogChannel & { close(): void | Promise<void> } {
|
|
17
19
|
return "close" in ch && typeof ch.close === "function";
|
|
18
20
|
}
|
|
19
21
|
|
|
@@ -45,6 +47,9 @@ export interface SpectrumAppContext {
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
export default class SpectrumProvider {
|
|
50
|
+
/** The logger this provider bound, so shutdown only clears its own. */
|
|
51
|
+
#owned: Logger | undefined;
|
|
52
|
+
|
|
48
53
|
#channels: LogChannel[] = [];
|
|
49
54
|
|
|
50
55
|
constructor(protected app: SpectrumAppContext) {}
|
|
@@ -72,13 +77,46 @@ export default class SpectrumProvider {
|
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
async boot() {
|
|
75
|
-
|
|
80
|
+
const logger = await this.app.container.resolve<Logger>(Logger);
|
|
81
|
+
this.#owned = logger;
|
|
82
|
+
setLogger(logger);
|
|
76
83
|
}
|
|
77
84
|
|
|
78
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Release channel resources (e.g. FileChannel WriteStreams) on shutdown.
|
|
87
|
+
*
|
|
88
|
+
* AWAITED, and all of them: closing a file channel ends a stream, and ending
|
|
89
|
+
* one is a request rather than a completion. Firing them and returning let
|
|
90
|
+
* the shutdown run on to `process.exit` with the last lines still buffered.
|
|
91
|
+
* `allSettled` so one channel failing to close does not strand the others.
|
|
92
|
+
*/
|
|
79
93
|
async shutdown() {
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
// Release the module-level singleton first, while it is still ours: past
|
|
95
|
+
// this point the channels are closing, and a logger reachable through
|
|
96
|
+
// `services/main` would be writing into streams that have ended.
|
|
97
|
+
if (this.#owned !== undefined && getLogger() === this.#owned) clearLogger();
|
|
98
|
+
this.#owned = undefined;
|
|
99
|
+
const results = await Promise.allSettled(
|
|
100
|
+
this.#channels
|
|
101
|
+
.filter((channel) => hasClose(channel))
|
|
102
|
+
.map(async (channel) => channel.close()),
|
|
103
|
+
);
|
|
104
|
+
// `allSettled` keeps one failure from stranding the others — that is why
|
|
105
|
+
// it is here — but the results were then thrown away. A channel that
|
|
106
|
+
// could not flush is lost log, and losing it silently during shutdown is
|
|
107
|
+
// how the lines explaining the shutdown disappear. Reported to stderr
|
|
108
|
+
// because the logger is exactly what has just been taken down.
|
|
109
|
+
const failures = results.filter(
|
|
110
|
+
(result): result is PromiseRejectedResult => result.status === "rejected",
|
|
111
|
+
);
|
|
112
|
+
for (const failure of failures) {
|
|
113
|
+
const reason =
|
|
114
|
+
failure.reason instanceof Error
|
|
115
|
+
? failure.reason.message
|
|
116
|
+
: String(failure.reason);
|
|
117
|
+
process.stderr.write(
|
|
118
|
+
`[spectrum] a channel failed to close; log written just before shutdown may be missing: ${reason}\n`,
|
|
119
|
+
);
|
|
82
120
|
}
|
|
83
121
|
}
|
|
84
122
|
|
|
@@ -128,13 +128,26 @@ export class FileChannel implements LogChannel {
|
|
|
128
128
|
return this.#currentSize > 0 && this.#currentSize + bytes > this.#maxSize;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/** The rotation in flight, so `close()` can wait for it. */
|
|
132
|
+
#rotation: Promise<void> | null = null;
|
|
133
|
+
|
|
131
134
|
#scheduleRotation(): void {
|
|
132
135
|
if (this.#rotating || this.#closed) return;
|
|
133
136
|
this.#rotating = true;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
// The promise is KEPT, not just started. A rotation renames files and
|
|
138
|
+
// opens a new stream; `close()` arriving in the middle of that used to
|
|
139
|
+
// write the buffer to a stream the rotation was replacing and return,
|
|
140
|
+
// while the renames carried on behind it. The last lines — the ones
|
|
141
|
+
// explaining why the process is going down — could land in a file that
|
|
142
|
+
// was about to be moved, or in one nothing would look at.
|
|
143
|
+
this.#rotation = new Promise<void>((resolve) => {
|
|
144
|
+
queueMicrotask(() => {
|
|
145
|
+
this.#rotate().finally(() => {
|
|
146
|
+
this.#rotating = false;
|
|
147
|
+
this.#flushPending();
|
|
148
|
+
this.#rotation = null;
|
|
149
|
+
resolve();
|
|
150
|
+
});
|
|
138
151
|
});
|
|
139
152
|
});
|
|
140
153
|
}
|
|
@@ -215,14 +228,43 @@ export class FileChannel implements LogChannel {
|
|
|
215
228
|
* the flag is set before the flush so nothing the flush triggers can reopen
|
|
216
229
|
* the file.
|
|
217
230
|
*/
|
|
218
|
-
close(): void {
|
|
231
|
+
close(): Promise<void> {
|
|
232
|
+
// Every caller awaits the SAME completion — the promise itself, not a
|
|
233
|
+
// wrapper around it, which is why this is not `async`. Returning early on `#closed`
|
|
234
|
+
// meant a second `close()` resolved while the first was still flushing,
|
|
235
|
+
// so a shutdown that closed two channels in parallel — or simply called
|
|
236
|
+
// this twice — believed the last lines were on disk when they were still
|
|
237
|
+
// in the stream.
|
|
238
|
+
this.#closing ??= this.#close();
|
|
239
|
+
return this.#closing;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** The single closing run, memoised by {@link close}. */
|
|
243
|
+
#closing?: Promise<void>;
|
|
244
|
+
|
|
245
|
+
async #close(): Promise<void> {
|
|
219
246
|
if (this.#closed) return;
|
|
220
|
-
|
|
247
|
+
// Closed FIRST, so nothing the rotation's flush triggers schedules
|
|
248
|
+
// another one, then wait for the rotation already in flight. Without
|
|
249
|
+
// this the two ran over each other and whichever finished last decided
|
|
250
|
+
// where the final lines were.
|
|
221
251
|
this.#closed = true;
|
|
252
|
+
await this.#rotation;
|
|
253
|
+
const pending = this.#pending.splice(0);
|
|
222
254
|
if (this.#stream) {
|
|
223
|
-
|
|
224
|
-
|
|
255
|
+
const stream = this.#stream;
|
|
256
|
+
for (const line of pending) stream.write(line);
|
|
225
257
|
this.#stream = null;
|
|
258
|
+
// AWAIT the flush. `end()` asks the stream to finish; it does not
|
|
259
|
+
// finish it. Returning here let a shutdown run on to `process.exit`
|
|
260
|
+
// with the last lines still buffered — and the last lines are usually
|
|
261
|
+
// the ones explaining why the process is going down.
|
|
262
|
+
await new Promise<void>((resolve) => {
|
|
263
|
+
stream.end(() => resolve());
|
|
264
|
+
// A stream that errors will never emit `finish`, and a shutdown
|
|
265
|
+
// must not hang on a full disk or a revoked permission.
|
|
266
|
+
stream.once("error", () => resolve());
|
|
267
|
+
});
|
|
226
268
|
return;
|
|
227
269
|
}
|
|
228
270
|
// No stream, because a rotation is in flight: it nulls the stream before
|
package/src/services/main.ts
CHANGED
|
@@ -23,6 +23,18 @@ export function getLogger(): Logger | undefined {
|
|
|
23
23
|
return instance;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @internal Release the singleton, so a shut-down application does not leave a
|
|
28
|
+
* dead logger reachable through `services/main`.
|
|
29
|
+
*
|
|
30
|
+
* The caller checks ownership first (`getLogger() === mine`): two applications
|
|
31
|
+
* share this module in one process, and the one shutting down must not clear
|
|
32
|
+
* what the other has since bound.
|
|
33
|
+
*/
|
|
34
|
+
export function clearLogger(): void {
|
|
35
|
+
instance = undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
const logger: Logger = new Proxy({} as Logger, {
|
|
27
39
|
get(_target, prop) {
|
|
28
40
|
if (!instance) {
|
package/src/types.ts
CHANGED
|
@@ -85,6 +85,16 @@ export type { TransportTargetOptions } from "./targets.js";
|
|
|
85
85
|
export interface LogChannel {
|
|
86
86
|
name: string;
|
|
87
87
|
write(entry: LogEntry): void;
|
|
88
|
+
/**
|
|
89
|
+
* Release whatever the channel holds open, and finish writing.
|
|
90
|
+
*
|
|
91
|
+
* Allowed to be asynchronous, and that is the point: a file channel ends a
|
|
92
|
+
* stream, and ending one is a request, not a completion. Returning before
|
|
93
|
+
* the `finish` event meant a shutdown could reach `process.exit` with the
|
|
94
|
+
* last lines still in the kernel's hands — the lines about why the process
|
|
95
|
+
* was shutting down, most of the time.
|
|
96
|
+
*/
|
|
97
|
+
close?(): void | Promise<void>;
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
/** Transforms a value before it is written (pino `serializers` parity). */
|