@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/RustLogBridge.js
CHANGED
|
@@ -5,8 +5,17 @@
|
|
|
5
5
|
* through the Spectrum Logger so both Rust and TS logs appear in
|
|
6
6
|
* the same stream with the same format.
|
|
7
7
|
*
|
|
8
|
+
* Every stderr write in the process goes through the bridge, not only the
|
|
9
|
+
* Rust crates' — `console.error`, a child process, a library echoing request
|
|
10
|
+
* data. So a line is claimed only when its module is on an allow-list
|
|
11
|
+
* (`ream-*` by default), it is written through the Logger (its level,
|
|
12
|
+
* `enabled`, serializers and redaction apply) and it carries
|
|
13
|
+
* `source: 'rust'`. Before that, any `[FATAL anything] text` that reached
|
|
14
|
+
* stderr became a genuine-looking structured entry.
|
|
15
|
+
*
|
|
8
16
|
* @implements FR55
|
|
9
17
|
*/
|
|
18
|
+
const DEFAULT_MODULES = /^ream-/;
|
|
10
19
|
/**
|
|
11
20
|
* Parse a Rust log line into a Spectrum LogEntry.
|
|
12
21
|
* Supports common Rust log formats:
|
|
@@ -43,18 +52,6 @@ export function parseRustLog(line) {
|
|
|
43
52
|
timestamp: new Date().toISOString(),
|
|
44
53
|
};
|
|
45
54
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Create a bridge that captures stderr and routes Rust logs to Spectrum channels.
|
|
48
|
-
*
|
|
49
|
-
* Usage — pass the same channels array you built the Logger with (Logger.config
|
|
50
|
-
* is private, so reuse the array rather than reaching into the instance):
|
|
51
|
-
* const channels = [new ConsoleChannel('pretty')]
|
|
52
|
-
* const logger = new Logger({ level: 'info', channels })
|
|
53
|
-
* const bridge = createRustLogBridge(channels)
|
|
54
|
-
* bridge.start()
|
|
55
|
-
* // ... Rust crates emit to stderr
|
|
56
|
-
* bridge.stop()
|
|
57
|
-
*/
|
|
58
55
|
/**
|
|
59
56
|
* `process.stderr.write` exactly as it was found, so `stop()` puts THAT back.
|
|
60
57
|
*
|
|
@@ -97,8 +94,33 @@ function passThrough(write, chunk, encoding, done) {
|
|
|
97
94
|
// callback in the slot the three-argument form expects.
|
|
98
95
|
return write.call(process.stderr, chunk, encoding, done);
|
|
99
96
|
}
|
|
100
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Create a bridge that captures stderr and routes Rust logs through `logger`.
|
|
99
|
+
*
|
|
100
|
+
* const logger = new Logger({ level: 'info', channels: [new ConsoleChannel('pretty')] })
|
|
101
|
+
* const bridge = createRustLogBridge(logger)
|
|
102
|
+
* bridge.start()
|
|
103
|
+
* // ... Rust crates emit to stderr
|
|
104
|
+
* bridge.stop()
|
|
105
|
+
*/
|
|
106
|
+
export function createRustLogBridge(logger, options = {}) {
|
|
107
|
+
const modules = options.modules ?? DEFAULT_MODULES;
|
|
101
108
|
let bridgingDepth = 0;
|
|
109
|
+
/** A claimed line, through the logger, its own writes passed straight on. */
|
|
110
|
+
const emit = (entry) => {
|
|
111
|
+
bridgingDepth++;
|
|
112
|
+
try {
|
|
113
|
+
logger
|
|
114
|
+
.child({ module: entry.module, source: "rust" })
|
|
115
|
+
.log(entry.level, entry.message);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// The bridge must never break a stderr write.
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
bridgingDepth--;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
102
124
|
const bridge = {
|
|
103
125
|
start() {
|
|
104
126
|
if (activeBridge === bridge)
|
|
@@ -132,13 +154,11 @@ export function createRustLogBridge(channels) {
|
|
|
132
154
|
}
|
|
133
155
|
const str = typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk);
|
|
134
156
|
let hadRustLog = false;
|
|
135
|
-
// Rebuild passthrough
|
|
136
|
-
//
|
|
137
|
-
// the separator, so every segment except a trailing fragment (the
|
|
157
|
+
// Rebuild passthrough byte-faithfully: split("\n") drops the
|
|
158
|
+
// separator, so every segment except a trailing fragment (the
|
|
138
159
|
// chunk didn't end in "\n") was newline-terminated originally —
|
|
139
|
-
// reattach accordingly.
|
|
140
|
-
//
|
|
141
|
-
// in their original order.
|
|
160
|
+
// reattach accordingly. Text ahead of a claimed line is written
|
|
161
|
+
// before it, so the order a reader sees is the order written.
|
|
142
162
|
let passthrough = "";
|
|
143
163
|
const segments = str.split("\n");
|
|
144
164
|
for (let i = 0; i < segments.length; i++) {
|
|
@@ -148,21 +168,15 @@ export function createRustLogBridge(channels) {
|
|
|
148
168
|
const trimmed = seg.trim();
|
|
149
169
|
// Only a complete, non-empty line is a Rust-log candidate. A
|
|
150
170
|
// trailing fragment is a partial write — never parse or drop it.
|
|
151
|
-
const
|
|
171
|
+
const parsed = trimmed && !isTrailingFragment ? parseRustLog(trimmed) : null;
|
|
172
|
+
const entry = parsed !== null && modules.test(parsed.module) ? parsed : null;
|
|
152
173
|
if (entry) {
|
|
153
174
|
hadRustLog = true;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
channel.write(entry);
|
|
158
|
-
}
|
|
159
|
-
catch {
|
|
160
|
-
/* ignore */
|
|
161
|
-
}
|
|
162
|
-
finally {
|
|
163
|
-
bridgingDepth--;
|
|
164
|
-
}
|
|
175
|
+
if (passthrough) {
|
|
176
|
+
passThrough(origWrite, passthrough, undefined, undefined);
|
|
177
|
+
passthrough = "";
|
|
165
178
|
}
|
|
179
|
+
emit(entry);
|
|
166
180
|
}
|
|
167
181
|
else {
|
|
168
182
|
passthrough += original;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RustLogBridge.js","sourceRoot":"","sources":["../src/RustLogBridge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"RustLogBridge.js","sourceRoot":"","sources":["../src/RustLogBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAaH,MAAM,eAAe,GAAG,QAAQ,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACxC,kCAAkC;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACvD,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,MAAM,QAAQ,GAA6B;QAC1C,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO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1B,CAAC;KACD,CAAC;IAEF,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import "./augmentations.js";
|
|
2
|
+
/**
|
|
3
|
+
* The slice of a container the provider uses. Answers `unknown` rather than a
|
|
4
|
+
* caller-chosen `T`: what comes back is checked, not asserted.
|
|
5
|
+
*/
|
|
2
6
|
interface SpectrumContainer {
|
|
3
7
|
singleton(token: unknown, factory: () => unknown): void;
|
|
4
|
-
resolve
|
|
8
|
+
resolve(token: unknown): Promise<unknown>;
|
|
5
9
|
}
|
|
6
10
|
interface SpectrumConfigStore {
|
|
7
|
-
get
|
|
11
|
+
get(key: string): unknown;
|
|
8
12
|
}
|
|
9
13
|
export interface SpectrumAppContext {
|
|
10
14
|
container: SpectrumContainer;
|
|
@@ -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;AAgD5B;;;GAGG;AACH,UAAU,iBAAiB;IAC1B,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI,CAAC;IACxD,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1C;AAED,UAAU,mBAAmB;IAC5B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;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;IAqBF,IAAI;IAwCV;;;;;;;OAOG;IACG,QAAQ;CAkFd"}
|
package/dist/SpectrumProvider.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import "./augmentations.js";
|
|
2
2
|
import { ConsoleChannel } from "./channels/ConsoleChannel.js";
|
|
3
|
+
import { SpectrumError } from "./errors.js";
|
|
4
|
+
import { onLog } from "./events.js";
|
|
3
5
|
import { Logger } from "./Logger.js";
|
|
4
6
|
import { LoggerManager } from "./LoggerManager.js";
|
|
5
7
|
import { clearLogger, getLogger, setLogger } from "./services/main.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
+
import { channelsFromConfig } from "./targets.js";
|
|
9
|
+
import { assertLogLevel, logLevel } from "./types.js";
|
|
10
|
+
/** An emitter, as far as this provider is concerned. Structural: no import. */
|
|
11
|
+
function hasEmit(value) {
|
|
12
|
+
return (typeof value === "object" &&
|
|
13
|
+
value !== null &&
|
|
14
|
+
"emit" in value &&
|
|
15
|
+
typeof value.emit === "function");
|
|
16
|
+
}
|
|
8
17
|
/** A channel that owns a resource (e.g. a FileChannel WriteStream) to release on shutdown. */
|
|
9
18
|
function hasClose(ch) {
|
|
10
19
|
return "close" in ch && typeof ch.close === "function";
|
|
@@ -44,9 +53,40 @@ export default class SpectrumProvider {
|
|
|
44
53
|
}
|
|
45
54
|
async boot() {
|
|
46
55
|
const logger = await this.app.container.resolve(Logger);
|
|
56
|
+
if (!(logger instanceof Logger)) {
|
|
57
|
+
throw new SpectrumError("E_SPECTRUM_LOGGER_NOT_BOUND", "the container resolved something other than a Logger for the Logger token");
|
|
58
|
+
}
|
|
47
59
|
this.#owned = logger;
|
|
48
60
|
setLogger(logger);
|
|
61
|
+
await this.#bridgeLogEvents();
|
|
49
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Bridge spectrum's `onLog` registry onto the app emitter as `log:line`,
|
|
65
|
+
* the way atlas bridges its queries as `db:query`.
|
|
66
|
+
*
|
|
67
|
+
* That is what lets something outside the logger — the debug toolbar's log
|
|
68
|
+
* panel — see a line without importing spectrum. No-op when the container
|
|
69
|
+
* exposes no `events` emitter; `onLog` stays the way to observe.
|
|
70
|
+
*/
|
|
71
|
+
async #bridgeLogEvents() {
|
|
72
|
+
let emitter;
|
|
73
|
+
try {
|
|
74
|
+
emitter = await this.app.container.resolve("events");
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return; // no emitter bound
|
|
78
|
+
}
|
|
79
|
+
if (!hasEmit(emitter))
|
|
80
|
+
return;
|
|
81
|
+
// Idempotent: a boot that failed past this point and retried would
|
|
82
|
+
// otherwise emit every line twice.
|
|
83
|
+
this.#logBridge?.();
|
|
84
|
+
this.#logBridge = onLog((entry) => {
|
|
85
|
+
emitter.emit("log:line", entry);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** Unsubscribe for the `onLog` → app-emitter bridge, torn down on shutdown. */
|
|
89
|
+
#logBridge;
|
|
50
90
|
/**
|
|
51
91
|
* Release channel resources (e.g. FileChannel WriteStreams) on shutdown.
|
|
52
92
|
*
|
|
@@ -59,6 +99,8 @@ export default class SpectrumProvider {
|
|
|
59
99
|
// Release the module-level singleton first, while it is still ours: past
|
|
60
100
|
// this point the channels are closing, and a logger reachable through
|
|
61
101
|
// `services/main` would be writing into streams that have ended.
|
|
102
|
+
this.#logBridge?.();
|
|
103
|
+
this.#logBridge = undefined;
|
|
62
104
|
if (this.#owned !== undefined && getLogger() === this.#owned)
|
|
63
105
|
clearLogger();
|
|
64
106
|
this.#owned = undefined;
|
|
@@ -101,9 +143,11 @@ export default class SpectrumProvider {
|
|
|
101
143
|
return { default: "app", loggers: { app: this.#normalizeLogger(flat) } };
|
|
102
144
|
}
|
|
103
145
|
#normalizeLogger(cfg) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
146
|
+
// An invalid level in the config is a config error, not a cue to take
|
|
147
|
+
// whatever the environment says instead.
|
|
148
|
+
const level = cfg.level === undefined
|
|
149
|
+
? logLevel(process.env.LOG_LEVEL)
|
|
150
|
+
: assertLogLevel(cfg.level);
|
|
107
151
|
// An AdonisJS `config/logger.ts` declares its output as
|
|
108
152
|
// `transport.targets`, not as channels. It has to be converted HERE:
|
|
109
153
|
// filling `channels` in with the console fallback below is what stopped
|
|
@@ -113,15 +157,11 @@ export default class SpectrumProvider {
|
|
|
113
157
|
const channels = this.#channelsFor(cfg, level);
|
|
114
158
|
return { ...cfg, level, channels };
|
|
115
159
|
}
|
|
116
|
-
/** Explicit channels, else the declared targets, else a pretty console. */
|
|
160
|
+
/** Explicit channels, else the declared destination or targets, else a pretty console. */
|
|
117
161
|
#channelsFor(cfg, level) {
|
|
118
162
|
if (cfg.channels && cfg.channels.length > 0)
|
|
119
163
|
return cfg.channels;
|
|
120
|
-
|
|
121
|
-
if (declared && declared.length > 0) {
|
|
122
|
-
return channelsFromTargets(declared, level);
|
|
123
|
-
}
|
|
124
|
-
return [new ConsoleChannel("pretty")];
|
|
164
|
+
return channelsFromConfig(cfg, level) ?? [new ConsoleChannel("pretty")];
|
|
125
165
|
}
|
|
126
166
|
}
|
|
127
167
|
//# sourceMappingURL=SpectrumProvider.js.map
|
|
@@ -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,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"SpectrumProvider.js","sourceRoot":"","sources":["../src/SpectrumProvider.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB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,EAAE,GAAG,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;IAC1E,CAAC;IAED,gBAAgB,CAAC,GAAuB;QACvC,sEAAsE;QACtE,yCAAyC;QACzC,MAAM,KAAK,GACV,GAAG,CAAC,KAAK,KAAK,SAAS;YACtB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;YACjC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,wDAAwD;QACxD,qEAAqE;QACrE,wEAAwE;QACxE,oEAAoE;QACpE,yEAAyE;QACzE,oEAAoE;QACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IACpC,CAAC;IAED,0FAA0F;IAC1F,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,OAAO,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzE,CAAC;CACD"}
|
|
@@ -4,10 +4,17 @@
|
|
|
4
4
|
* @implements FR57, FR58
|
|
5
5
|
*/
|
|
6
6
|
import type { LogChannel, LogEntry } from "../types.js";
|
|
7
|
+
export interface ConsoleChannelOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Write every level to this one stream. Without it, error and fatal go to
|
|
10
|
+
* stderr and the rest to stdout.
|
|
11
|
+
*/
|
|
12
|
+
stream?: "stdout" | "stderr";
|
|
13
|
+
}
|
|
7
14
|
export declare class ConsoleChannel implements LogChannel {
|
|
8
15
|
#private;
|
|
9
16
|
name: string;
|
|
10
|
-
constructor(format?: "pretty" | "json");
|
|
17
|
+
constructor(format?: "pretty" | "json", options?: ConsoleChannelOptions);
|
|
11
18
|
write(entry: LogEntry): void;
|
|
12
19
|
}
|
|
13
20
|
//# sourceMappingURL=ConsoleChannel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConsoleChannel.d.ts","sourceRoot":"","sources":["../../src/channels/ConsoleChannel.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"ConsoleChannel.d.ts","sourceRoot":"","sources":["../../src/channels/ConsoleChannel.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGxD,MAAM,WAAW,qBAAqB;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC7B;AAED,qBAAa,cAAe,YAAW,UAAU;;IAChD,IAAI,SAAa;gBAKhB,MAAM,GAAE,QAAQ,GAAG,MAAiB,EACpC,OAAO,GAAE,qBAA0B;IAMpC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;CAoF5B"}
|
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @implements FR57, FR58
|
|
5
5
|
*/
|
|
6
|
+
import { jsonLine, lineOptionsFor } from "../jsonLine.js";
|
|
6
7
|
import { sanitizeLogValue } from "../sanitize.js";
|
|
8
|
+
import { stringifyRecord } from "../stringify.js";
|
|
7
9
|
import { logEntryExtras } from "../types.js";
|
|
8
10
|
export class ConsoleChannel {
|
|
9
11
|
name = "console";
|
|
10
12
|
#format;
|
|
11
|
-
|
|
13
|
+
#stream;
|
|
14
|
+
constructor(format = "pretty", options = {}) {
|
|
12
15
|
this.#format = format;
|
|
16
|
+
this.#stream = options.stream;
|
|
13
17
|
}
|
|
14
18
|
write(entry) {
|
|
15
19
|
if (this.#format === "json") {
|
|
@@ -22,15 +26,7 @@ export class ConsoleChannel {
|
|
|
22
26
|
#writeJson(entry) {
|
|
23
27
|
// Structural fields first, then merged root fields spread flat (pino
|
|
24
28
|
// output parity). Legacy `data` (if present) stays under its own key.
|
|
25
|
-
const output =
|
|
26
|
-
timestamp: entry.timestamp,
|
|
27
|
-
level: entry.level,
|
|
28
|
-
module: entry.module,
|
|
29
|
-
message: entry.message,
|
|
30
|
-
correlationId: entry.correlationId,
|
|
31
|
-
data: entry.data,
|
|
32
|
-
...logEntryExtras(entry),
|
|
33
|
-
});
|
|
29
|
+
const output = jsonLine(entry);
|
|
34
30
|
this.#writeToStream(entry.level, `${output}\n`);
|
|
35
31
|
}
|
|
36
32
|
#sanitize(str) {
|
|
@@ -51,17 +47,25 @@ export class ConsoleChannel {
|
|
|
51
47
|
: "";
|
|
52
48
|
const cid = cidRaw ? ` cid=${this.#sanitize(cidRaw)}` : "";
|
|
53
49
|
// Prefer legacy `data`; otherwise render the merged root fields. JSON
|
|
54
|
-
//
|
|
50
|
+
// escapes C0 controls but not DEL, C1 or U+2028/2029, so the rendered
|
|
51
|
+
// data goes through the same sanitizer as the message.
|
|
55
52
|
const extras = logEntryExtras(entry);
|
|
56
53
|
const payload = entry.data ?? (Object.keys(extras).length > 0 ? extras : undefined);
|
|
57
|
-
const dataStr = payload
|
|
54
|
+
const dataStr = payload
|
|
55
|
+
? ` ${this.#sanitize(stringifyRecord(payload, lineOptionsFor(entry).limits))}`
|
|
56
|
+
: "";
|
|
58
57
|
const message = this.#sanitize(entry.message);
|
|
59
58
|
const module = this.#sanitize(entry.module);
|
|
60
59
|
this.#writeToStream(entry.level, `${prefix} ${time} ${levelStr} [${module}] ${message}${cid}${dataStr}\n`);
|
|
61
60
|
}
|
|
62
|
-
/**
|
|
61
|
+
/** The configured stream, else error/fatal to stderr and others to stdout. */
|
|
63
62
|
#writeToStream(level, output) {
|
|
64
|
-
if (
|
|
63
|
+
if (this.#stream === "stdout") {
|
|
64
|
+
process.stdout.write(output);
|
|
65
|
+
}
|
|
66
|
+
else if (this.#stream === "stderr" ||
|
|
67
|
+
level === "error" ||
|
|
68
|
+
level === "fatal") {
|
|
65
69
|
process.stderr.write(output);
|
|
66
70
|
}
|
|
67
71
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConsoleChannel.js","sourceRoot":"","sources":["../../src/channels/ConsoleChannel.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ConsoleChannel.js","sourceRoot":"","sources":["../../src/channels/ConsoleChannel.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAU7C,MAAM,OAAO,cAAc;IAC1B,IAAI,GAAG,SAAS,CAAC;IACjB,OAAO,CAAoB;IAClB,OAAO,CAAkC;IAElD,YACC,SAA4B,QAAQ,EACpC,UAAiC,EAAE;QAEnC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,KAAe;QACpB,IAAI,IAAI,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;YAC7B,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;IACF,CAAC;IAED,UAAU,CAAC,KAAe;QACzB,qEAAqE;QACrE,sEAAsE;QACtE,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AAO,GAAG,CAAC;YACZ,KAAK,OAAO;gBACX,OAAO,GAAG,CAAC;YACZ;gBACC,OAAO,GAAG,CAAC;QACb,CAAC;IACF,CAAC;CACD"}
|
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* File logging channel — writes log entries to a file as JSON lines.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* HTTP hot path
|
|
4
|
+
* `write()` never touches the disk: it queues the line and returns. One
|
|
5
|
+
* asynchronous pump opens the file, writes the queue in order, and rotates it
|
|
6
|
+
* when the next line would cross `maxSizeBytes`, so the HTTP hot path never
|
|
7
|
+
* waits on the filesystem.
|
|
8
|
+
*
|
|
9
|
+
* Two promises hold that together, both as pino's file destination keeps them:
|
|
10
|
+
* a line accepted before the process exits is on disk after it (the queue is
|
|
11
|
+
* written synchronously on `exit`), and a destination that stops keeping up
|
|
12
|
+
* costs bounded memory (past `maxBufferBytes` lines are dropped and counted,
|
|
13
|
+
* and the count is written once the queue drains).
|
|
7
14
|
*
|
|
8
15
|
* @implements MISS-14, MISS-15
|
|
9
16
|
*/
|
|
10
17
|
import type { LogChannel, LogEntry } from "../types.js";
|
|
11
18
|
export interface FileChannelConfig {
|
|
12
|
-
|
|
19
|
+
/** The file to append to (created, with its directory, if missing). */
|
|
20
|
+
path?: string;
|
|
21
|
+
/**
|
|
22
|
+
* An already-open descriptor to write to instead of a path — what a
|
|
23
|
+
* `destination: 3` target names. Never rotated, and left open on close:
|
|
24
|
+
* the channel did not open it.
|
|
25
|
+
*/
|
|
26
|
+
fd?: number;
|
|
27
|
+
/** `false` starts the file over on first open instead of appending. Default true. */
|
|
28
|
+
append?: boolean;
|
|
29
|
+
/** Rotate before the live file would grow past this. Default 10 MiB. */
|
|
13
30
|
maxSizeBytes?: number;
|
|
31
|
+
/** Files kept, the live one included. Default 5. */
|
|
14
32
|
maxFiles?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Bytes accepted but not yet written that the channel will hold. Past it,
|
|
35
|
+
* new lines are dropped and counted. Default 16 MiB.
|
|
36
|
+
*/
|
|
37
|
+
maxBufferBytes?: number;
|
|
15
38
|
}
|
|
16
39
|
export declare class FileChannel implements LogChannel {
|
|
17
40
|
#private;
|
|
@@ -19,12 +42,12 @@ export declare class FileChannel implements LogChannel {
|
|
|
19
42
|
constructor(config: FileChannelConfig);
|
|
20
43
|
write(entry: LogEntry): void;
|
|
21
44
|
/**
|
|
22
|
-
* Stop writing, for good.
|
|
45
|
+
* Stop writing, for good, once everything accepted is on disk.
|
|
23
46
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* the
|
|
47
|
+
* Every caller awaits the SAME completion — the promise itself, not a
|
|
48
|
+
* wrapper around it, which is why this is not `async`. A second `close()`
|
|
49
|
+
* that resolved while the first was still flushing let a shutdown believe
|
|
50
|
+
* the last lines were on disk when they were still queued.
|
|
28
51
|
*/
|
|
29
52
|
close(): Promise<void>;
|
|
30
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileChannel.d.ts","sourceRoot":"","sources":["../../src/channels/FileChannel.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"FileChannel.d.ts","sourceRoot":"","sources":["../../src/channels/FileChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAQH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,WAAW,iBAAiB;IACjC,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qFAAqF;IACrF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AA8BD,qBAAa,WAAY,YAAW,UAAU;;IAC7C,IAAI,SAAU;gBA8BF,MAAM,EAAE,iBAAiB;IAiCrC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAgN5B;;;;;;;OAOG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAuCtB"}
|