@c9up/spectrum 0.1.12 → 0.1.13
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 +1 -0
- package/dist/SpectrumProvider.d.ts.map +1 -1
- package/dist/SpectrumProvider.js +30 -21
- 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.map +1 -1
- package/dist/channels/FileChannel.js +26 -6
- 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/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 +28 -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 +34 -25
- package/src/augmentations.ts +32 -0
- package/src/channels/FileChannel.ts +30 -6
- package/src/configure.ts +19 -7
- package/src/index.ts +4 -0
- package/src/redact.ts +100 -0
- package/src/targets.ts +78 -12
- package/src/types.ts +50 -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
5
|
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
|
-
}
|
|
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";
|
|
@@ -39,9 +31,14 @@ export default class SpectrumProvider {
|
|
|
39
31
|
this.#channels = Object.values(managerConfig.loggers).flatMap((logger) => logger.channels ?? []);
|
|
40
32
|
const manager = new LoggerManager(managerConfig);
|
|
41
33
|
this.app.container.singleton(Logger, () => manager);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
// Namespaced by the package that owns it, the way upstream namespaces
|
|
35
|
+
// `lucid.db`, `auth.manager` and `drive.manager` by theirs. The bare
|
|
36
|
+
// token stays bound beside it: it is what every existing
|
|
37
|
+
// `container.make(...)` asks for, and a token is not worth breaking an
|
|
38
|
+
// application over.
|
|
39
|
+
const logger = () => this.app.container.resolve(Logger);
|
|
40
|
+
this.app.container.singleton("spectrum.logger", logger);
|
|
41
|
+
this.app.container.singleton("logger", logger);
|
|
45
42
|
}
|
|
46
43
|
async boot() {
|
|
47
44
|
setLogger(await this.app.container.resolve(Logger));
|
|
@@ -76,15 +73,27 @@ export default class SpectrumProvider {
|
|
|
76
73
|
return { default: "app", loggers: { app: this.#normalizeLogger(flat) } };
|
|
77
74
|
}
|
|
78
75
|
#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)
|
|
76
|
+
const level = isLogLevelWithSilent(cfg.level)
|
|
85
77
|
? cfg.level
|
|
86
|
-
:
|
|
78
|
+
: logLevel(process.env.LOG_LEVEL);
|
|
79
|
+
// An AdonisJS `config/logger.ts` declares its output as
|
|
80
|
+
// `transport.targets`, not as channels. It has to be converted HERE:
|
|
81
|
+
// filling `channels` in with the console fallback below is what stopped
|
|
82
|
+
// the Logger's own conversion from ever running (it only fires when
|
|
83
|
+
// `channels` is absent), so a config that declared a file target reached
|
|
84
|
+
// production writing to a console and nothing to the file it named.
|
|
85
|
+
const channels = this.#channelsFor(cfg, level);
|
|
87
86
|
return { ...cfg, level, channels };
|
|
88
87
|
}
|
|
88
|
+
/** Explicit channels, else the declared targets, else a pretty console. */
|
|
89
|
+
#channelsFor(cfg, level) {
|
|
90
|
+
if (cfg.channels && cfg.channels.length > 0)
|
|
91
|
+
return cfg.channels;
|
|
92
|
+
const declared = cfg.transport?.targets;
|
|
93
|
+
if (declared && declared.length > 0) {
|
|
94
|
+
return channelsFromTargets(declared, level);
|
|
95
|
+
}
|
|
96
|
+
return [new ConsoleChannel("pretty")];
|
|
97
|
+
}
|
|
89
98
|
}
|
|
90
99
|
//# 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,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,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAOnD,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5D,8FAA8F;AAC9F,SAAS,QAAQ,CAAC,EAAc;IAC/B,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;IAGd;IAFtB,SAAS,GAAiB,EAAE,CAAC;IAE7B,YAA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,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;IACH,KAAK,IAAI,IAAI;CAoCb"}
|
|
@@ -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;
|
|
@@ -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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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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mB,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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact.js","sourceRoot":"","sources":["../src/redact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;GAGG;AACH,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC3C,MAAM,MAAM,GAAG,IAA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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;CACvB;AAED,2EAA2E;AAC3E,MAAM,WAAW,mBAAmB;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,8CAA8C;AAC9C,qBAAa,OAAO;;IAGnB,IAAI,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI;IAKzC,oDAAoD;IACpD,MAAM,CACL,WAAW,EAAE,OAAO,EACpB,KAAK,EAAE,sBAAsB,GAAG,CAAC,MAAM,sBAAsB,CAAC,GAC5D,IAAI;IAOP,iDAAiD;IACjD,UAAU,CACT,WAAW,EAAE,OAAO,EACpB,KAAK,EAAE,sBAAsB,GAAG,CAAC,MAAM,sBAAsB,CAAC,GAC5D,IAAI;IAIP,OAAO,IAAI,sBAAsB,EAAE;CAGnC;AAED,iBAAS,UAAU,CAClB,OAAO,GAAE,iBAAsB,EAC/B,KAAK,CAAC,EAAE,kBAAkB,GAAG,MAAM,GACjC,sBAAsB,CAExB;AAED,iBAAS,YAAY,CACpB,OAAO,GAAE,mBAAwB,EACjC,KAAK,CAAC,EAAE,kBAAkB,GAAG,MAAM,GACjC,sBAAsB,CAExB;AAED,yFAAyF;AACzF,eAAO,MAAM,OAAO,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG;IACvC,IAAI,EAAE,OAAO,UAAU,CAAC;IACxB,MAAM,EAAE,OAAO,YAAY,CAAC;CAI3B,CAAC;AAqDH;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,SAAS,sBAAsB,EAAE,EACvC,cAAc,CAAC,EAAE,kBAAkB,GAAG,MAAM,GAC1C,UAAU,EAAE,CA+Bd"}
|
package/dist/targets.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { ConsoleChannel } from "./channels/ConsoleChannel.js";
|
|
17
17
|
import { FileChannel } from "./channels/FileChannel.js";
|
|
18
|
+
import { isLogLevelWithSilent, LOG_LEVEL_ORDER, levelThreshold, } from "./types.js";
|
|
18
19
|
/** Builds the targets array conditionally. */
|
|
19
20
|
export class Targets {
|
|
20
21
|
#targets = [];
|
|
@@ -49,6 +50,53 @@ export const targets = Object.assign(() => new Targets(), {
|
|
|
49
50
|
file: fileTarget,
|
|
50
51
|
pretty: prettyTarget,
|
|
51
52
|
});
|
|
53
|
+
/**
|
|
54
|
+
* A channel that only sees the entries its target's own level admits.
|
|
55
|
+
*
|
|
56
|
+
* `targets.file({ destination: 'app.log' }, 'error')` is a statement about that
|
|
57
|
+
* destination, not about the logger: upstream gives every transport its own
|
|
58
|
+
* level and pino filters per target. Dropping it sent every debug line — request
|
|
59
|
+
* bodies, tokens, whatever the app logs while it is being debugged — into the
|
|
60
|
+
* file the deployment had scoped down to errors.
|
|
61
|
+
*/
|
|
62
|
+
class LeveledChannel {
|
|
63
|
+
name;
|
|
64
|
+
#inner;
|
|
65
|
+
#threshold;
|
|
66
|
+
constructor(inner, threshold) {
|
|
67
|
+
this.#inner = inner;
|
|
68
|
+
this.#threshold = threshold;
|
|
69
|
+
this.name = inner.name;
|
|
70
|
+
}
|
|
71
|
+
write(entry) {
|
|
72
|
+
if (LOG_LEVEL_ORDER[entry.level] < this.#threshold)
|
|
73
|
+
return;
|
|
74
|
+
this.#inner.write(entry);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Forwarded because the wrapper is now what the provider holds, and a
|
|
78
|
+
* FileChannel that is never closed keeps its stream open past shutdown.
|
|
79
|
+
*/
|
|
80
|
+
close() {
|
|
81
|
+
const inner = this.#inner;
|
|
82
|
+
inner.close?.();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Gate a channel on a target level, when the target names one. */
|
|
86
|
+
function atLevel(channel, level) {
|
|
87
|
+
if (level === undefined)
|
|
88
|
+
return channel;
|
|
89
|
+
if (!isLogLevelWithSilent(level)) {
|
|
90
|
+
// A level nobody can act on is a config error, and the failure mode of
|
|
91
|
+
// ignoring it is the destination receiving everything.
|
|
92
|
+
throw new Error(`[spectrum] Unknown transport target level "${level}". Use one of: ${Object.keys(LOG_LEVEL_ORDER).join(", ")}, silent.`);
|
|
93
|
+
}
|
|
94
|
+
const threshold = levelThreshold(level);
|
|
95
|
+
// `trace` admits everything the logger already let through.
|
|
96
|
+
if (threshold <= LOG_LEVEL_ORDER.trace)
|
|
97
|
+
return channel;
|
|
98
|
+
return new LeveledChannel(channel, threshold);
|
|
99
|
+
}
|
|
52
100
|
/**
|
|
53
101
|
* Turn transport targets into the channels spectrum actually writes through.
|
|
54
102
|
*
|
|
@@ -56,17 +104,23 @@ export const targets = Object.assign(() => new Targets(), {
|
|
|
56
104
|
* file when `destination` is a path, and to the console when it is a file
|
|
57
105
|
* descriptor, which is what `destination: 1` means in a containerised app that
|
|
58
106
|
* ships stdout to its log collector.
|
|
107
|
+
*
|
|
108
|
+
* A target with no level of its own inherits `inheritedLevel`, the level of the
|
|
109
|
+
* logger it belongs to — upstream's `defineConfig` fills the same gap, by
|
|
110
|
+
* writing the level into the target. Passing it instead of writing it leaves
|
|
111
|
+
* the caller's config object alone.
|
|
59
112
|
*/
|
|
60
|
-
export function channelsFromTargets(list) {
|
|
113
|
+
export function channelsFromTargets(list, inheritedLevel) {
|
|
61
114
|
const channels = [];
|
|
62
115
|
for (const entry of list) {
|
|
116
|
+
const level = entry.level ?? inheritedLevel;
|
|
63
117
|
if (entry.target === "pino-pretty") {
|
|
64
|
-
channels.push(new ConsoleChannel("pretty"));
|
|
118
|
+
channels.push(atLevel(new ConsoleChannel("pretty"), level));
|
|
65
119
|
continue;
|
|
66
120
|
}
|
|
67
121
|
const destination = entry.options?.destination;
|
|
68
122
|
if (typeof destination === "string") {
|
|
69
|
-
channels.push(new FileChannel({
|
|
123
|
+
channels.push(atLevel(new FileChannel({
|
|
70
124
|
path: destination,
|
|
71
125
|
...(typeof entry.options?.maxSizeBytes === "number"
|
|
72
126
|
? { maxSizeBytes: entry.options.maxSizeBytes }
|
|
@@ -74,12 +128,12 @@ export function channelsFromTargets(list) {
|
|
|
74
128
|
...(typeof entry.options?.maxFiles === "number"
|
|
75
129
|
? { maxFiles: entry.options.maxFiles }
|
|
76
130
|
: {}),
|
|
77
|
-
}));
|
|
131
|
+
}), level));
|
|
78
132
|
continue;
|
|
79
133
|
}
|
|
80
134
|
// A descriptor (or nothing) means the process's own output, as JSON —
|
|
81
135
|
// the shape a log collector parses.
|
|
82
|
-
channels.push(new ConsoleChannel("json"));
|
|
136
|
+
channels.push(atLevel(new ConsoleChannel("json"), level));
|
|
83
137
|
}
|
|
84
138
|
return channels;
|
|
85
139
|
}
|
package/dist/targets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"targets.js","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"targets.js","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EACN,oBAAoB,EACpB,eAAe,EACf,cAAc,GACd,MAAM,YAAY,CAAC;AAsBpB,8CAA8C;AAC9C,MAAM,OAAO,OAAO;IACV,QAAQ,GAA6B,EAAE,CAAC;IAEjD,IAAI,CAAC,KAA6B;QACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,oDAAoD;IACpD,MAAM,CACL,WAAoB,EACpB,KAA8D;QAE9D,0EAA0E;QAC1E,yCAAyC;QACzC,IAAI,WAAW;YAAE,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,K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