@c9up/spectrum 0.1.17 → 0.1.19
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 +23 -6
- package/dist/Logger.d.ts +6 -2
- package/dist/Logger.d.ts.map +1 -1
- package/dist/Logger.js +195 -72
- package/dist/Logger.js.map +1 -1
- package/dist/LoggerManager.d.ts +5 -0
- package/dist/LoggerManager.d.ts.map +1 -1
- package/dist/LoggerManager.js +10 -3
- package/dist/LoggerManager.js.map +1 -1
- package/dist/RustLogBridge.d.ts +27 -2
- package/dist/RustLogBridge.d.ts.map +1 -1
- package/dist/RustLogBridge.js +45 -31
- package/dist/RustLogBridge.js.map +1 -1
- package/dist/SpectrumProvider.d.ts +6 -2
- package/dist/SpectrumProvider.d.ts.map +1 -1
- package/dist/SpectrumProvider.js +51 -11
- package/dist/SpectrumProvider.js.map +1 -1
- package/dist/channels/ConsoleChannel.d.ts +8 -1
- package/dist/channels/ConsoleChannel.d.ts.map +1 -1
- package/dist/channels/ConsoleChannel.js +18 -14
- package/dist/channels/ConsoleChannel.js.map +1 -1
- package/dist/channels/FileChannel.d.ts +32 -9
- package/dist/channels/FileChannel.d.ts.map +1 -1
- package/dist/channels/FileChannel.js +264 -202
- package/dist/channels/FileChannel.js.map +1 -1
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +38 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +55 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/jsonLine.d.ts +49 -0
- package/dist/jsonLine.d.ts.map +1 -0
- package/dist/jsonLine.js +164 -0
- package/dist/jsonLine.js.map +1 -0
- package/dist/redact.d.ts +16 -3
- package/dist/redact.d.ts.map +1 -1
- package/dist/redact.js +121 -10
- package/dist/redact.js.map +1 -1
- package/dist/sanitize.d.ts +11 -5
- package/dist/sanitize.d.ts.map +1 -1
- package/dist/sanitize.js +36 -12
- package/dist/sanitize.js.map +1 -1
- package/dist/services/main.d.ts.map +1 -1
- package/dist/services/main.js +12 -1
- package/dist/services/main.js.map +1 -1
- package/dist/stdSerializers.d.ts +47 -0
- package/dist/stdSerializers.d.ts.map +1 -0
- package/dist/stdSerializers.js +128 -0
- package/dist/stdSerializers.js.map +1 -0
- package/dist/stringify.d.ts +33 -0
- package/dist/stringify.d.ts.map +1 -0
- package/dist/stringify.js +148 -0
- package/dist/stringify.js.map +1 -0
- package/dist/targets.d.ts +29 -7
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +130 -31
- package/dist/targets.js.map +1 -1
- package/dist/testing/FakeLogger.js +20 -5
- package/dist/testing/FakeLogger.js.map +1 -1
- package/dist/types.d.ts +71 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +18 -2
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/Logger.ts +259 -79
- package/src/LoggerManager.ts +10 -3
- package/src/RustLogBridge.ts +59 -30
- package/src/SpectrumProvider.ts +69 -17
- package/src/channels/ConsoleChannel.ts +30 -14
- package/src/channels/FileChannel.ts +319 -220
- package/src/errors.ts +13 -0
- package/src/events.ts +62 -0
- package/src/index.ts +18 -3
- package/src/jsonLine.ts +222 -0
- package/src/redact.ts +133 -9
- package/src/sanitize.ts +36 -12
- package/src/services/main.ts +13 -1
- package/src/stdSerializers.ts +146 -0
- package/src/stringify.ts +175 -0
- package/src/targets.ts +193 -42
- package/src/testing/FakeLogger.ts +23 -5
- package/src/types.ts +97 -4
- package/stubs/config/logger.stub +1 -1
package/dist/targets.js
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { ConsoleChannel } from "./channels/ConsoleChannel.js";
|
|
17
17
|
import { FileChannel } from "./channels/FileChannel.js";
|
|
18
|
+
import { SpectrumError } from "./errors.js";
|
|
19
|
+
import { jsonLine } from "./jsonLine.js";
|
|
18
20
|
import { isLogLevelWithSilent, LOG_LEVEL_ORDER, levelThreshold, } from "./types.js";
|
|
19
21
|
/** Builds the targets array conditionally. */
|
|
20
22
|
export class Targets {
|
|
@@ -75,11 +77,12 @@ class LeveledChannel {
|
|
|
75
77
|
}
|
|
76
78
|
/**
|
|
77
79
|
* Forwarded because the wrapper is now what the provider holds, and a
|
|
78
|
-
* FileChannel that is never closed keeps its
|
|
80
|
+
* FileChannel that is never closed keeps its file open past shutdown.
|
|
81
|
+
* The inner promise is handed back: dropping it let shutdown resolve
|
|
82
|
+
* before any line of a file target was flushed.
|
|
79
83
|
*/
|
|
80
84
|
close() {
|
|
81
|
-
|
|
82
|
-
inner.close?.();
|
|
85
|
+
return this.#inner.close?.();
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
/** Gate a channel on a target level, when the target names one. */
|
|
@@ -89,7 +92,7 @@ function atLevel(channel, level) {
|
|
|
89
92
|
if (!isLogLevelWithSilent(level)) {
|
|
90
93
|
// A level nobody can act on is a config error, and the failure mode of
|
|
91
94
|
// ignoring it is the destination receiving everything.
|
|
92
|
-
throw new
|
|
95
|
+
throw new SpectrumError("E_SPECTRUM_UNKNOWN_LEVEL", `Unknown transport target level "${level}". Use one of: ${Object.keys(LOG_LEVEL_ORDER).join(", ")}, silent.`);
|
|
93
96
|
}
|
|
94
97
|
const threshold = levelThreshold(level);
|
|
95
98
|
// `trace` admits everything the logger already let through.
|
|
@@ -97,13 +100,29 @@ function atLevel(channel, level) {
|
|
|
97
100
|
return channel;
|
|
98
101
|
return new LeveledChannel(channel, threshold);
|
|
99
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* JSON to a file descriptor, every level to that one descriptor, as pino's
|
|
105
|
+
* file target writes it. Splitting by level sent a `destination: 1` app's
|
|
106
|
+
* errors to stderr, where a collector reading stdout never saw them, and
|
|
107
|
+
* ignored any other descriptor. No destination means 1, as upstream.
|
|
108
|
+
*/
|
|
109
|
+
function descriptorChannel(destination) {
|
|
110
|
+
if (destination === undefined || destination === 1) {
|
|
111
|
+
return new ConsoleChannel("json", { stream: "stdout" });
|
|
112
|
+
}
|
|
113
|
+
if (destination === 2)
|
|
114
|
+
return new ConsoleChannel("json", { stream: "stderr" });
|
|
115
|
+
if (typeof destination === "number")
|
|
116
|
+
return new FileChannel({ fd: destination });
|
|
117
|
+
throw new SpectrumError("E_SPECTRUM_INVALID_FILE_OPTIONS", `pino/file destination must be a path or a file descriptor, got ${typeof destination}`);
|
|
118
|
+
}
|
|
100
119
|
/**
|
|
101
120
|
* Turn transport targets into the channels spectrum actually writes through.
|
|
102
121
|
*
|
|
103
122
|
* `pino-pretty` is the human-readable console; `pino/file` writes JSON — to a
|
|
104
|
-
* file when `destination` is a path, and to
|
|
105
|
-
*
|
|
106
|
-
*
|
|
123
|
+
* file when `destination` is a path, and to that descriptor when it is one:
|
|
124
|
+
* `destination: 1` is stdout, which a containerised app ships to its log
|
|
125
|
+
* collector.
|
|
107
126
|
*
|
|
108
127
|
* A target with no level of its own inherits `inheritedLevel`, the level of the
|
|
109
128
|
* logger it belongs to — upstream's `defineConfig` fills the same gap, by
|
|
@@ -111,30 +130,110 @@ function atLevel(channel, level) {
|
|
|
111
130
|
* the caller's config object alone.
|
|
112
131
|
*/
|
|
113
132
|
export function channelsFromTargets(list, inheritedLevel) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
return list.map((entry) => atLevel(channelForTarget(entry), entry.level ?? inheritedLevel));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The channel a target describes.
|
|
137
|
+
*
|
|
138
|
+
* Any other target name used to fall through to JSON on stdout, so a config
|
|
139
|
+
* shipping logs to Loki or a socket booted fine and nothing reached the sink.
|
|
140
|
+
* Upstream fails when it cannot load a target; so does this.
|
|
141
|
+
*/
|
|
142
|
+
function channelForTarget(entry) {
|
|
143
|
+
const { target } = entry;
|
|
144
|
+
const options = entry.options ?? {};
|
|
145
|
+
if (typeof target !== "string")
|
|
146
|
+
return target;
|
|
147
|
+
if (target === "pino-pretty")
|
|
148
|
+
return prettyChannel(options.destination);
|
|
149
|
+
if (target === "pino/file") {
|
|
150
|
+
const destination = options.destination;
|
|
151
|
+
if (typeof destination !== "string")
|
|
152
|
+
return descriptorChannel(destination);
|
|
153
|
+
return new FileChannel({
|
|
154
|
+
path: destination,
|
|
155
|
+
append: optionalBoolean(options, "append"),
|
|
156
|
+
maxSizeBytes: optionalNumber(options, "maxSizeBytes"),
|
|
157
|
+
maxFiles: optionalNumber(options, "maxFiles"),
|
|
158
|
+
maxBufferBytes: optionalNumber(options, "maxBufferBytes"),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
throw new SpectrumError("E_SPECTRUM_UNSUPPORTED_TARGET", `Transport target "${target}" is not supported: spectrum builds "pino-pretty" and "pino/file". Pass a LogChannel as the target to write anywhere else.`);
|
|
162
|
+
}
|
|
163
|
+
function prettyChannel(destination) {
|
|
164
|
+
if (destination === undefined)
|
|
165
|
+
return new ConsoleChannel("pretty");
|
|
166
|
+
if (destination === 1)
|
|
167
|
+
return new ConsoleChannel("pretty", { stream: "stdout" });
|
|
168
|
+
if (destination === 2)
|
|
169
|
+
return new ConsoleChannel("pretty", { stream: "stderr" });
|
|
170
|
+
throw new SpectrumError("E_SPECTRUM_UNSUPPORTED_TARGET", `pino-pretty destination ${JSON.stringify(destination)} is not supported: use 1 or 2, or a pino/file target for a file.`);
|
|
171
|
+
}
|
|
172
|
+
/** A number option, or undefined when absent; any other type is a config error. */
|
|
173
|
+
function optionalNumber(options, key) {
|
|
174
|
+
const value = options[key];
|
|
175
|
+
if (value === undefined || typeof value === "number")
|
|
176
|
+
return value;
|
|
177
|
+
throw invalidOption(key, "number", value);
|
|
178
|
+
}
|
|
179
|
+
/** A boolean option, or undefined when absent; any other type is a config error. */
|
|
180
|
+
function optionalBoolean(options, key) {
|
|
181
|
+
const value = options[key];
|
|
182
|
+
if (value === undefined || typeof value === "boolean")
|
|
183
|
+
return value;
|
|
184
|
+
throw invalidOption(key, "boolean", value);
|
|
185
|
+
}
|
|
186
|
+
function invalidOption(key, type, value) {
|
|
187
|
+
return new SpectrumError("E_SPECTRUM_INVALID_FILE_OPTIONS", `pino/file option ${key} must be a ${type}, got ${typeof value}`);
|
|
188
|
+
}
|
|
189
|
+
/** JSON lines to anything with a `write(line)` method. */
|
|
190
|
+
class WritableChannel {
|
|
191
|
+
name = "destination";
|
|
192
|
+
#target;
|
|
193
|
+
constructor(target) {
|
|
194
|
+
this.#target = target;
|
|
195
|
+
}
|
|
196
|
+
write(entry) {
|
|
197
|
+
this.#target.write(`${jsonLine(entry)}\n`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function isLineWritable(value) {
|
|
201
|
+
return (typeof value === "object" &&
|
|
202
|
+
value !== null &&
|
|
203
|
+
"write" in value &&
|
|
204
|
+
typeof value.write === "function");
|
|
205
|
+
}
|
|
206
|
+
/** The channel a logger's `destination` option names. */
|
|
207
|
+
export function destinationChannel(destination) {
|
|
208
|
+
if (typeof destination === "string")
|
|
209
|
+
return new FileChannel({ path: destination });
|
|
210
|
+
if (typeof destination === "number")
|
|
211
|
+
return descriptorChannel(destination);
|
|
212
|
+
if (isLineWritable(destination))
|
|
213
|
+
return new WritableChannel(destination);
|
|
214
|
+
throw new SpectrumError("E_SPECTRUM_UNSUPPORTED_TARGET", "destination must be a path, a file descriptor or an object with a write(line) method");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The channels a config's `destination` or `transport` describe, or
|
|
218
|
+
* `undefined` when it declares neither. `destination` wins over `transport`,
|
|
219
|
+
* as upstream; a transport is either a `targets` list or one
|
|
220
|
+
* `{ target, options }`.
|
|
221
|
+
*/
|
|
222
|
+
export function channelsFromConfig(config, level) {
|
|
223
|
+
if (config.destination !== undefined) {
|
|
224
|
+
return [destinationChannel(config.destination)];
|
|
225
|
+
}
|
|
226
|
+
const transport = config.transport;
|
|
227
|
+
if (transport === undefined)
|
|
228
|
+
return undefined;
|
|
229
|
+
if ("target" in transport)
|
|
230
|
+
return channelsFromTargets([transport], level);
|
|
231
|
+
if (Reflect.get(transport, "pipeline") !== undefined) {
|
|
232
|
+
throw new SpectrumError("E_SPECTRUM_UNSUPPORTED_TARGET", "transport.pipeline is not supported: declare targets, or pass channels");
|
|
233
|
+
}
|
|
234
|
+
if (transport.targets === undefined || transport.targets.length === 0) {
|
|
235
|
+
return undefined;
|
|
137
236
|
}
|
|
138
|
-
return
|
|
237
|
+
return channelsFromTargets(transport.targets, level);
|
|
139
238
|
}
|
|
140
239
|
//# sourceMappingURL=targets.js.map
|
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;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQzC,OAA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AA+B,EAC/B,sFAAsF,CACtF,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CACjC,MAAoD,EACpD,KAA8C;IAE9C,IAAI,MAAM,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACtC,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACnC,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC9C,IAAI,QAAQ,IAAI,SAAS;QAAE,OAAO,mBAAmB,CAAC,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;IAC1E,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;QACtD,MAAM,IAAI,aAAa,CACtB,+BAA+B,EAC/B,wEAAwE,CACxE,CAAC;IACH,CAAC;IACD,IAAI,SAAS,CAAC,OAAO,KAAK,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvE,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,mBAAmB,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Not re-exported from the main barrel; reach via
|
|
8
8
|
* `@c9up/spectrum/testing`.
|
|
9
9
|
*/
|
|
10
|
-
import { logEntryExtras } from "../types.js";
|
|
10
|
+
import { LOG_LEVEL_ORDER, logEntryExtras } from "../types.js";
|
|
11
11
|
export class FakeLogger {
|
|
12
12
|
name = "fake";
|
|
13
13
|
#captured = [];
|
|
@@ -103,9 +103,9 @@ function safeStringify(value) {
|
|
|
103
103
|
return "<unstringifiable>";
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
function deepClone(
|
|
106
|
+
function deepClone(entry) {
|
|
107
107
|
try {
|
|
108
|
-
return structuredClone(
|
|
108
|
+
return structuredClone(entry);
|
|
109
109
|
}
|
|
110
110
|
catch {
|
|
111
111
|
// `data` can carry functions / class instances that structuredClone
|
|
@@ -115,11 +115,26 @@ function deepClone(value) {
|
|
|
115
115
|
// instead of thrown away (the throw propagated into Logger.log's swallow,
|
|
116
116
|
// dropping the entry and making assertLogged fail with "no entry").
|
|
117
117
|
try {
|
|
118
|
-
|
|
118
|
+
const parsed = JSON.parse(safeStringify(entry));
|
|
119
|
+
return isLogEntry(parsed) ? parsed : entry;
|
|
119
120
|
}
|
|
120
121
|
catch {
|
|
121
|
-
return
|
|
122
|
+
return entry;
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
125
|
}
|
|
126
|
+
/** What came back from the JSON round-trip still has the shape of an entry. */
|
|
127
|
+
function isLogEntry(value) {
|
|
128
|
+
return (typeof value === "object" &&
|
|
129
|
+
value !== null &&
|
|
130
|
+
"level" in value &&
|
|
131
|
+
typeof value.level === "string" &&
|
|
132
|
+
value.level in LOG_LEVEL_ORDER &&
|
|
133
|
+
"message" in value &&
|
|
134
|
+
typeof value.message === "string" &&
|
|
135
|
+
"module" in value &&
|
|
136
|
+
typeof value.module === "string" &&
|
|
137
|
+
"timestamp" in value &&
|
|
138
|
+
typeof value.timestamp === "string");
|
|
139
|
+
}
|
|
125
140
|
//# sourceMappingURL=FakeLogger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FakeLogger.js","sourceRoot":"","sources":["../../src/testing/FakeLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"FakeLogger.js","sourceRoot":"","sources":["../../src/testing/FakeLogger.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAa9D,MAAM,OA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MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;YACzD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;QAC5C,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;AACF,CAAC;AAED,+EAA+E;AAC/E,SAAS,UAAU,CAAC,KAAc;IACjC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,IAAI,KAAK;QAChB,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QAC/B,KAAK,CAAC,KAAK,IAAI,eAAe;QAC9B,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,QAAQ,IAAI,KAAK;QACjB,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;QAChC,WAAW,IAAI,KAAK;QACpB,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,CACnC,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LineFormatters, TimestampOption } from "./jsonLine.js";
|
|
1
2
|
import type { TransportTargetOptions } from "./targets.js";
|
|
2
3
|
/**
|
|
3
4
|
* Spectrum types.
|
|
@@ -21,9 +22,18 @@ export declare const SILENT_THRESHOLD: number;
|
|
|
21
22
|
export declare function levelThreshold(level: LogLevelWithSilent): number;
|
|
22
23
|
/** Whether a value is a level a config may name. */
|
|
23
24
|
export declare function isLogLevelWithSilent(value: unknown): value is LogLevelWithSilent;
|
|
25
|
+
/**
|
|
26
|
+
* A configured level, checked.
|
|
27
|
+
*
|
|
28
|
+
* An unknown level is a config error, as it is upstream ("unknown level"):
|
|
29
|
+
* reading `ERROR` or `warning` as `info` meant an operator quieting production
|
|
30
|
+
* got more output, and no word about it.
|
|
31
|
+
*/
|
|
32
|
+
export declare function assertLogLevel(value: unknown): LogLevelWithSilent;
|
|
24
33
|
/**
|
|
25
34
|
* Narrow an untyped level — `process.env.LOG_LEVEL`, a CLI flag — to one the
|
|
26
|
-
* config can name
|
|
35
|
+
* config can name. Absent (or empty) falls back to `fallback`; set to
|
|
36
|
+
* something that is no level, it throws.
|
|
27
37
|
*
|
|
28
38
|
* Without it a config file has to assert the env string into the union, and an
|
|
29
39
|
* assertion is the wrong tool for a value that comes from outside the program:
|
|
@@ -68,7 +78,31 @@ export type LogSerializer = (value: unknown) => unknown;
|
|
|
68
78
|
/** Redaction config (pino `redact` parity). */
|
|
69
79
|
export interface RedactOptions {
|
|
70
80
|
paths: string[];
|
|
71
|
-
|
|
81
|
+
/**
|
|
82
|
+
* What a matched value becomes. A function is called with the value and
|
|
83
|
+
* the path it was found at (wildcards resolved). Default `[Redacted]`.
|
|
84
|
+
*/
|
|
85
|
+
censor?: string | ((value: unknown, path: string[]) => unknown);
|
|
86
|
+
/** Remove matched keys instead of censoring them. */
|
|
87
|
+
remove?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** Called with each log call's arguments; calls `method` to write (pino `hooks.logMethod`). */
|
|
90
|
+
export type LogMethodHook = (this: unknown, args: unknown[], method: (...args: unknown[]) => void, level: number) => void;
|
|
91
|
+
/** Fields to add to every line, computed per call (pino `mixin`). */
|
|
92
|
+
export type LogMixin = (mergeObject: Record<string, unknown>, level: number, logger: unknown) => Record<string, unknown>;
|
|
93
|
+
/** Options of `logger.child(bindings, options)`. */
|
|
94
|
+
export interface ChildOptions {
|
|
95
|
+
level?: LogLevelWithSilent;
|
|
96
|
+
/** Replaces the parent's redaction for this child. */
|
|
97
|
+
redact?: string[] | RedactOptions;
|
|
98
|
+
/** Added to (and overriding) the parent's serializers. */
|
|
99
|
+
serializers?: Record<string, LogSerializer>;
|
|
100
|
+
/** Appended to the parent's prefix, written before every message. */
|
|
101
|
+
msgPrefix?: string;
|
|
102
|
+
}
|
|
103
|
+
/** Anything with a `write(line)` method, used as a JSON destination. */
|
|
104
|
+
export interface LineWritable {
|
|
105
|
+
write(line: string): unknown;
|
|
72
106
|
}
|
|
73
107
|
/**
|
|
74
108
|
* Configuration for a single logger. Mirrors the surface of `@adonisjs/logger`
|
|
@@ -98,13 +132,47 @@ export interface LogConfig {
|
|
|
98
132
|
*/
|
|
99
133
|
transport?: {
|
|
100
134
|
targets?: readonly TransportTargetOptions[];
|
|
101
|
-
};
|
|
135
|
+
} | TransportTargetOptions;
|
|
136
|
+
/**
|
|
137
|
+
* Where JSON lines go when no `channels` are given: a file path, a file
|
|
138
|
+
* descriptor, or anything with a `write(line)` method. Wins over
|
|
139
|
+
* `transport`, as upstream.
|
|
140
|
+
*/
|
|
141
|
+
destination?: string | number | LineWritable;
|
|
102
142
|
/** Per-module level overrides — spectrum divergence. */
|
|
103
143
|
modules?: Record<string, LogLevelWithSilent>;
|
|
104
144
|
/** Keys / dot-paths to redact on the merging object before writing. */
|
|
105
145
|
redact?: string[] | RedactOptions;
|
|
106
146
|
/** Per-key value serializers (`err`/`error` handled by default). */
|
|
107
147
|
serializers?: Record<string, LogSerializer>;
|
|
148
|
+
/**
|
|
149
|
+
* How deep a value JSON cannot write (a cycle, a BigInt) is walked before
|
|
150
|
+
* `"[Object]"` stands in for the rest. Default 5, as pino.
|
|
151
|
+
*/
|
|
152
|
+
depthLimit?: number;
|
|
153
|
+
/** How many entries of one such object or array are written. Default 100, as pino. */
|
|
154
|
+
edgeLimit?: number;
|
|
155
|
+
/** The key a JSON line carries the message under. Default `msg`. */
|
|
156
|
+
messageKey?: string;
|
|
157
|
+
/** How a JSON line writes `time`. Default `'epoch'` (milliseconds). */
|
|
158
|
+
timestamp?: TimestampOption;
|
|
159
|
+
/** Fields on every JSON line. Default `{ pid, hostname }`; `null` for none. */
|
|
160
|
+
base?: Record<string, unknown> | null;
|
|
161
|
+
/** Reshape the level part and the merged fields of a JSON line. */
|
|
162
|
+
formatters?: LineFormatters;
|
|
163
|
+
/** The key an Error passed to a log call is written under. Default `err`. */
|
|
164
|
+
errorKey?: string;
|
|
165
|
+
/** Written before every message. */
|
|
166
|
+
msgPrefix?: string;
|
|
167
|
+
/** Fields added to every line, computed per call. A merging object wins over them. */
|
|
168
|
+
mixin?: LogMixin;
|
|
169
|
+
/** How the mixin's fields and the merging object combine. Default: merging object wins. */
|
|
170
|
+
mixinMergeStrategy?: (mergeObject: Record<string, unknown>, mixinObject: Record<string, unknown>) => Record<string, unknown>;
|
|
171
|
+
hooks?: {
|
|
172
|
+
logMethod?: LogMethodHook;
|
|
173
|
+
};
|
|
174
|
+
/** Called with every child logger created. */
|
|
175
|
+
onChild?: (child: unknown) => void;
|
|
108
176
|
}
|
|
109
177
|
/**
|
|
110
178
|
* Multi-logger config (Adonis `defineConfig` shape): a `default` logger name
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC3D;;;GAGG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE/E,2EAA2E;AAC3E,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAErD;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAOpD,CAAC;AAEF,mEAAmE;AACnE,eAAO,MAAM,gBAAgB,QAA2B,CAAC;AAEzD,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,KAAK,EAAE,kBAAkB,GAA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AWD,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMvE"}
|
package/dist/types.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SpectrumError } from "./errors.js";
|
|
1
2
|
/**
|
|
2
3
|
* The numeric value of each level, on pino's scale.
|
|
3
4
|
*
|
|
@@ -28,16 +29,31 @@ const CONFIGURED_LEVELS = new Set([
|
|
|
28
29
|
export function isLogLevelWithSilent(value) {
|
|
29
30
|
return typeof value === "string" && CONFIGURED_LEVELS.has(value);
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* A configured level, checked.
|
|
34
|
+
*
|
|
35
|
+
* An unknown level is a config error, as it is upstream ("unknown level"):
|
|
36
|
+
* reading `ERROR` or `warning` as `info` meant an operator quieting production
|
|
37
|
+
* got more output, and no word about it.
|
|
38
|
+
*/
|
|
39
|
+
export function assertLogLevel(value) {
|
|
40
|
+
if (isLogLevelWithSilent(value))
|
|
41
|
+
return value;
|
|
42
|
+
throw new SpectrumError("E_SPECTRUM_UNKNOWN_LEVEL", `unknown level ${JSON.stringify(value) ?? String(value)}. Use one of: ${[...CONFIGURED_LEVELS].join(", ")}.`);
|
|
43
|
+
}
|
|
31
44
|
/**
|
|
32
45
|
* Narrow an untyped level — `process.env.LOG_LEVEL`, a CLI flag — to one the
|
|
33
|
-
* config can name
|
|
46
|
+
* config can name. Absent (or empty) falls back to `fallback`; set to
|
|
47
|
+
* something that is no level, it throws.
|
|
34
48
|
*
|
|
35
49
|
* Without it a config file has to assert the env string into the union, and an
|
|
36
50
|
* assertion is the wrong tool for a value that comes from outside the program:
|
|
37
51
|
* it claims to know what it cannot. This checks.
|
|
38
52
|
*/
|
|
39
53
|
export function logLevel(raw, fallback = "info") {
|
|
40
|
-
|
|
54
|
+
if (raw === undefined || raw === "")
|
|
55
|
+
return fallback;
|
|
56
|
+
return assertLogLevel(raw);
|
|
41
57
|
}
|
|
42
58
|
const RESERVED_ENTRY_KEYS = new Set([
|
|
43
59
|
"level",
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAa5C;;;;;;;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;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC5C,IAAI,oBAAoB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,MAAM,IAAI,aAAa,CACtB,0BAA0B,EAC1B,iBAAiB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,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