@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/src/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SpectrumError } from "./errors.js";
|
|
2
|
+
import type { LineFormatters, TimestampOption } from "./jsonLine.js";
|
|
1
3
|
import type { TransportTargetOptions } from "./targets.js";
|
|
2
4
|
/**
|
|
3
5
|
* Spectrum types.
|
|
@@ -46,9 +48,25 @@ export function isLogLevelWithSilent(
|
|
|
46
48
|
return typeof value === "string" && CONFIGURED_LEVELS.has(value);
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
/**
|
|
52
|
+
* A configured level, checked.
|
|
53
|
+
*
|
|
54
|
+
* An unknown level is a config error, as it is upstream ("unknown level"):
|
|
55
|
+
* reading `ERROR` or `warning` as `info` meant an operator quieting production
|
|
56
|
+
* got more output, and no word about it.
|
|
57
|
+
*/
|
|
58
|
+
export function assertLogLevel(value: unknown): LogLevelWithSilent {
|
|
59
|
+
if (isLogLevelWithSilent(value)) return value;
|
|
60
|
+
throw new SpectrumError(
|
|
61
|
+
"E_SPECTRUM_UNKNOWN_LEVEL",
|
|
62
|
+
`unknown level ${JSON.stringify(value) ?? String(value)}. Use one of: ${[...CONFIGURED_LEVELS].join(", ")}.`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
49
66
|
/**
|
|
50
67
|
* Narrow an untyped level — `process.env.LOG_LEVEL`, a CLI flag — to one the
|
|
51
|
-
* config can name
|
|
68
|
+
* config can name. Absent (or empty) falls back to `fallback`; set to
|
|
69
|
+
* something that is no level, it throws.
|
|
52
70
|
*
|
|
53
71
|
* Without it a config file has to assert the env string into the union, and an
|
|
54
72
|
* assertion is the wrong tool for a value that comes from outside the program:
|
|
@@ -58,7 +76,8 @@ export function logLevel(
|
|
|
58
76
|
raw: unknown,
|
|
59
77
|
fallback: LogLevelWithSilent = "info",
|
|
60
78
|
): LogLevelWithSilent {
|
|
61
|
-
|
|
79
|
+
if (raw === undefined || raw === "") return fallback;
|
|
80
|
+
return assertLogLevel(raw);
|
|
62
81
|
}
|
|
63
82
|
|
|
64
83
|
export interface LogEntry {
|
|
@@ -103,7 +122,44 @@ export type LogSerializer = (value: unknown) => unknown;
|
|
|
103
122
|
/** Redaction config (pino `redact` parity). */
|
|
104
123
|
export interface RedactOptions {
|
|
105
124
|
paths: string[];
|
|
106
|
-
|
|
125
|
+
/**
|
|
126
|
+
* What a matched value becomes. A function is called with the value and
|
|
127
|
+
* the path it was found at (wildcards resolved). Default `[Redacted]`.
|
|
128
|
+
*/
|
|
129
|
+
censor?: string | ((value: unknown, path: string[]) => unknown);
|
|
130
|
+
/** Remove matched keys instead of censoring them. */
|
|
131
|
+
remove?: boolean;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Called with each log call's arguments; calls `method` to write (pino `hooks.logMethod`). */
|
|
135
|
+
export type LogMethodHook = (
|
|
136
|
+
this: unknown,
|
|
137
|
+
args: unknown[],
|
|
138
|
+
method: (...args: unknown[]) => void,
|
|
139
|
+
level: number,
|
|
140
|
+
) => void;
|
|
141
|
+
|
|
142
|
+
/** Fields to add to every line, computed per call (pino `mixin`). */
|
|
143
|
+
export type LogMixin = (
|
|
144
|
+
mergeObject: Record<string, unknown>,
|
|
145
|
+
level: number,
|
|
146
|
+
logger: unknown,
|
|
147
|
+
) => Record<string, unknown>;
|
|
148
|
+
|
|
149
|
+
/** Options of `logger.child(bindings, options)`. */
|
|
150
|
+
export interface ChildOptions {
|
|
151
|
+
level?: LogLevelWithSilent;
|
|
152
|
+
/** Replaces the parent's redaction for this child. */
|
|
153
|
+
redact?: string[] | RedactOptions;
|
|
154
|
+
/** Added to (and overriding) the parent's serializers. */
|
|
155
|
+
serializers?: Record<string, LogSerializer>;
|
|
156
|
+
/** Appended to the parent's prefix, written before every message. */
|
|
157
|
+
msgPrefix?: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Anything with a `write(line)` method, used as a JSON destination. */
|
|
161
|
+
export interface LineWritable {
|
|
162
|
+
write(line: string): unknown;
|
|
107
163
|
}
|
|
108
164
|
|
|
109
165
|
/**
|
|
@@ -132,13 +188,50 @@ export interface LogConfig {
|
|
|
132
188
|
* drives real output instead of being quietly ignored. Explicit `channels`
|
|
133
189
|
* win when both are given.
|
|
134
190
|
*/
|
|
135
|
-
transport?:
|
|
191
|
+
transport?:
|
|
192
|
+
| { targets?: readonly TransportTargetOptions[] }
|
|
193
|
+
| TransportTargetOptions;
|
|
194
|
+
/**
|
|
195
|
+
* Where JSON lines go when no `channels` are given: a file path, a file
|
|
196
|
+
* descriptor, or anything with a `write(line)` method. Wins over
|
|
197
|
+
* `transport`, as upstream.
|
|
198
|
+
*/
|
|
199
|
+
destination?: string | number | LineWritable;
|
|
136
200
|
/** Per-module level overrides — spectrum divergence. */
|
|
137
201
|
modules?: Record<string, LogLevelWithSilent>;
|
|
138
202
|
/** Keys / dot-paths to redact on the merging object before writing. */
|
|
139
203
|
redact?: string[] | RedactOptions;
|
|
140
204
|
/** Per-key value serializers (`err`/`error` handled by default). */
|
|
141
205
|
serializers?: Record<string, LogSerializer>;
|
|
206
|
+
/**
|
|
207
|
+
* How deep a value JSON cannot write (a cycle, a BigInt) is walked before
|
|
208
|
+
* `"[Object]"` stands in for the rest. Default 5, as pino.
|
|
209
|
+
*/
|
|
210
|
+
depthLimit?: number;
|
|
211
|
+
/** How many entries of one such object or array are written. Default 100, as pino. */
|
|
212
|
+
edgeLimit?: number;
|
|
213
|
+
/** The key a JSON line carries the message under. Default `msg`. */
|
|
214
|
+
messageKey?: string;
|
|
215
|
+
/** How a JSON line writes `time`. Default `'epoch'` (milliseconds). */
|
|
216
|
+
timestamp?: TimestampOption;
|
|
217
|
+
/** Fields on every JSON line. Default `{ pid, hostname }`; `null` for none. */
|
|
218
|
+
base?: Record<string, unknown> | null;
|
|
219
|
+
/** Reshape the level part and the merged fields of a JSON line. */
|
|
220
|
+
formatters?: LineFormatters;
|
|
221
|
+
/** The key an Error passed to a log call is written under. Default `err`. */
|
|
222
|
+
errorKey?: string;
|
|
223
|
+
/** Written before every message. */
|
|
224
|
+
msgPrefix?: string;
|
|
225
|
+
/** Fields added to every line, computed per call. A merging object wins over them. */
|
|
226
|
+
mixin?: LogMixin;
|
|
227
|
+
/** How the mixin's fields and the merging object combine. Default: merging object wins. */
|
|
228
|
+
mixinMergeStrategy?: (
|
|
229
|
+
mergeObject: Record<string, unknown>,
|
|
230
|
+
mixinObject: Record<string, unknown>,
|
|
231
|
+
) => Record<string, unknown>;
|
|
232
|
+
hooks?: { logMethod?: LogMethodHook };
|
|
233
|
+
/** Called with every child logger created. */
|
|
234
|
+
onChild?: (child: unknown) => void;
|
|
142
235
|
}
|
|
143
236
|
|
|
144
237
|
/**
|
package/stubs/config/logger.stub
CHANGED
|
@@ -12,7 +12,7 @@ export default defineConfig({
|
|
|
12
12
|
enabled: true,
|
|
13
13
|
name: process.env.APP_NAME ?? 'app',
|
|
14
14
|
// LOG_LEVEL comes from outside the program, so it is checked rather than
|
|
15
|
-
// asserted:
|
|
15
|
+
// asserted: unset reads as 'info', and a value that is no level throws.
|
|
16
16
|
level: logLevel(process.env.LOG_LEVEL),
|
|
17
17
|
transport: {
|
|
18
18
|
targets: targets()
|