@c9up/spectrum 0.1.18 → 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 +190 -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 +13 -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/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -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 +254 -79
- package/src/LoggerManager.ts +10 -3
- package/src/RustLogBridge.ts +59 -30
- package/src/SpectrumProvider.ts +26 -17
- package/src/channels/ConsoleChannel.ts +30 -14
- package/src/channels/FileChannel.ts +319 -220
- package/src/errors.ts +13 -0
- package/src/index.ts +17 -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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The standard serializers, in the shapes upstream's `stdSerializers` write:
|
|
3
|
+
* `err` for errors, `req` and `res` for Node's HTTP request and response.
|
|
4
|
+
*
|
|
5
|
+
* new Logger({ serializers: { req: stdSerializers.req, res: stdSerializers.res } })
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Serialize an Error the way pino's `err` serializer does. Non-Error values
|
|
9
|
+
* pass through untouched.
|
|
10
|
+
*
|
|
11
|
+
* `{ name, message, stack }` threw away everything the error was carrying.
|
|
12
|
+
* `err.code` is usually the one field a log search is keyed on, and the `cause`
|
|
13
|
+
* of a wrapped error is the half that says what actually failed — both were
|
|
14
|
+
* dropped, silently, by a serializer whose job is to keep them.
|
|
15
|
+
*
|
|
16
|
+
* `path` holds the errors being serialized above this one. An error met again
|
|
17
|
+
* on its own path is a cycle and is written as `"[Circular]"`, as upstream
|
|
18
|
+
* skips an error it has already tagged; without it `err.self = err` was copied
|
|
19
|
+
* down to the depth limit, and an error with k such references cost k^8 copies
|
|
20
|
+
* on the logging call. An error shared by two branches is not a cycle and is
|
|
21
|
+
* written in both.
|
|
22
|
+
*/
|
|
23
|
+
export declare function serializeError(value: unknown, path?: readonly Error[]): unknown;
|
|
24
|
+
/**
|
|
25
|
+
* An HTTP request as upstream's `req` serializer writes it: id, method, url,
|
|
26
|
+
* query, params, headers and the remote address. Headers are written as they
|
|
27
|
+
* are — censoring `authorization` or a cookie is what `redact` is for.
|
|
28
|
+
*/
|
|
29
|
+
export declare function serializeRequest(value: unknown): unknown;
|
|
30
|
+
/** An HTTP response as upstream's `res` serializer writes it: status and headers. */
|
|
31
|
+
export declare function serializeResponse(value: unknown): unknown;
|
|
32
|
+
export declare const stdSerializers: {
|
|
33
|
+
err: (value: unknown) => unknown;
|
|
34
|
+
req: (value: unknown) => unknown;
|
|
35
|
+
res: (value: unknown) => unknown;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Upstream's time functions, for `timestamp`: each returns the `,"time":…`
|
|
39
|
+
* fragment a JSON line carries.
|
|
40
|
+
*/
|
|
41
|
+
export declare const stdTimeFunctions: {
|
|
42
|
+
epochTime: () => string;
|
|
43
|
+
unixTime: () => string;
|
|
44
|
+
isoTime: () => string;
|
|
45
|
+
nullTime: () => string;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=stdSerializers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdSerializers.d.ts","sourceRoot":"","sources":["../src/stdSerializers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC7B,KAAK,EAAE,OAAO,EACd,IAAI,GAAE,SAAS,KAAK,EAAO,GACzB,OAAO,CA+BT;AAMD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAiCxD;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAYzD;AAED,eAAO,MAAM,cAAc,EAAE;IAC5B,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IACjC,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IACjC,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CAKjC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE;IAC9B,SAAS,EAAE,MAAM,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,MAAM,CAAC;CAMvB,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The standard serializers, in the shapes upstream's `stdSerializers` write:
|
|
3
|
+
* `err` for errors, `req` and `res` for Node's HTTP request and response.
|
|
4
|
+
*
|
|
5
|
+
* new Logger({ serializers: { req: stdSerializers.req, res: stdSerializers.res } })
|
|
6
|
+
*/
|
|
7
|
+
/** How far down a chain of nested errors to follow. */
|
|
8
|
+
const MAX_CAUSE_DEPTH = 8;
|
|
9
|
+
/**
|
|
10
|
+
* Serialize an Error the way pino's `err` serializer does. Non-Error values
|
|
11
|
+
* pass through untouched.
|
|
12
|
+
*
|
|
13
|
+
* `{ name, message, stack }` threw away everything the error was carrying.
|
|
14
|
+
* `err.code` is usually the one field a log search is keyed on, and the `cause`
|
|
15
|
+
* of a wrapped error is the half that says what actually failed — both were
|
|
16
|
+
* dropped, silently, by a serializer whose job is to keep them.
|
|
17
|
+
*
|
|
18
|
+
* `path` holds the errors being serialized above this one. An error met again
|
|
19
|
+
* on its own path is a cycle and is written as `"[Circular]"`, as upstream
|
|
20
|
+
* skips an error it has already tagged; without it `err.self = err` was copied
|
|
21
|
+
* down to the depth limit, and an error with k such references cost k^8 copies
|
|
22
|
+
* on the logging call. An error shared by two branches is not a cycle and is
|
|
23
|
+
* written in both.
|
|
24
|
+
*/
|
|
25
|
+
export function serializeError(value, path = []) {
|
|
26
|
+
if (!(value instanceof Error))
|
|
27
|
+
return value;
|
|
28
|
+
if (path.includes(value))
|
|
29
|
+
return "[Circular]";
|
|
30
|
+
if (path.length > MAX_CAUSE_DEPTH)
|
|
31
|
+
return "[cause chain too deep]";
|
|
32
|
+
const below = [...path, value];
|
|
33
|
+
// Own ENUMERABLE properties only, which on an Error means the ones it was
|
|
34
|
+
// given: `message`, `stack` and `name` are not among them.
|
|
35
|
+
const out = { ...value };
|
|
36
|
+
for (const [key, nested] of Object.entries(out)) {
|
|
37
|
+
if (nested instanceof Error)
|
|
38
|
+
out[key] = serializeError(nested, below);
|
|
39
|
+
}
|
|
40
|
+
// Upstream reads the constructor rather than `name`, so a subclass that
|
|
41
|
+
// never assigns `this.name` is still reported as itself, and it names the
|
|
42
|
+
// field `type` — which is what an Adonis log pipeline reads.
|
|
43
|
+
out.type =
|
|
44
|
+
typeof value.constructor === "function"
|
|
45
|
+
? value.constructor.name
|
|
46
|
+
: value.name;
|
|
47
|
+
out.message = value.message;
|
|
48
|
+
out.stack = value.stack;
|
|
49
|
+
if (value instanceof AggregateError && Array.isArray(value.errors)) {
|
|
50
|
+
out.aggregateErrors = value.errors.map((each) => serializeError(each, below));
|
|
51
|
+
}
|
|
52
|
+
if (value.cause !== undefined) {
|
|
53
|
+
out.cause = serializeError(value.cause, below);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function isRecord(value) {
|
|
58
|
+
return typeof value === "object" && value !== null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* An HTTP request as upstream's `req` serializer writes it: id, method, url,
|
|
62
|
+
* query, params, headers and the remote address. Headers are written as they
|
|
63
|
+
* are — censoring `authorization` or a cookie is what `redact` is for.
|
|
64
|
+
*/
|
|
65
|
+
export function serializeRequest(value) {
|
|
66
|
+
if (!isRecord(value))
|
|
67
|
+
return value;
|
|
68
|
+
const info = Reflect.get(value, "info");
|
|
69
|
+
const connection = isRecord(info) ? info : Reflect.get(value, "socket");
|
|
70
|
+
const id = Reflect.get(value, "id");
|
|
71
|
+
const originalUrl = Reflect.get(value, "originalUrl");
|
|
72
|
+
const pathValue = Reflect.get(value, "path");
|
|
73
|
+
const url = Reflect.get(value, "url");
|
|
74
|
+
const query = Reflect.get(value, "query");
|
|
75
|
+
const params = Reflect.get(value, "params");
|
|
76
|
+
return {
|
|
77
|
+
id: typeof id === "function"
|
|
78
|
+
? Reflect.apply(id, value, [])
|
|
79
|
+
: (id ?? (isRecord(info) ? Reflect.get(info, "id") : undefined)),
|
|
80
|
+
method: Reflect.get(value, "method"),
|
|
81
|
+
url: originalUrl
|
|
82
|
+
? originalUrl
|
|
83
|
+
: typeof pathValue === "string"
|
|
84
|
+
? pathValue
|
|
85
|
+
: isRecord(url)
|
|
86
|
+
? (Reflect.get(url, "path") ?? url)
|
|
87
|
+
: url,
|
|
88
|
+
...(query ? { query } : {}),
|
|
89
|
+
...(params ? { params } : {}),
|
|
90
|
+
headers: Reflect.get(value, "headers"),
|
|
91
|
+
remoteAddress: isRecord(connection)
|
|
92
|
+
? Reflect.get(connection, "remoteAddress")
|
|
93
|
+
: undefined,
|
|
94
|
+
remotePort: isRecord(connection)
|
|
95
|
+
? Reflect.get(connection, "remotePort")
|
|
96
|
+
: undefined,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** An HTTP response as upstream's `res` serializer writes it: status and headers. */
|
|
100
|
+
export function serializeResponse(value) {
|
|
101
|
+
if (!isRecord(value))
|
|
102
|
+
return value;
|
|
103
|
+
const getHeaders = Reflect.get(value, "getHeaders");
|
|
104
|
+
return {
|
|
105
|
+
statusCode: Reflect.get(value, "headersSent")
|
|
106
|
+
? Reflect.get(value, "statusCode")
|
|
107
|
+
: null,
|
|
108
|
+
headers: typeof getHeaders === "function"
|
|
109
|
+
? Reflect.apply(getHeaders, value, [])
|
|
110
|
+
: Reflect.get(value, "_headers"),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export const stdSerializers = {
|
|
114
|
+
err: (value) => serializeError(value),
|
|
115
|
+
req: serializeRequest,
|
|
116
|
+
res: serializeResponse,
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Upstream's time functions, for `timestamp`: each returns the `,"time":…`
|
|
120
|
+
* fragment a JSON line carries.
|
|
121
|
+
*/
|
|
122
|
+
export const stdTimeFunctions = {
|
|
123
|
+
epochTime: () => `,"time":${Date.now()}`,
|
|
124
|
+
unixTime: () => `,"time":${Math.round(Date.now() / 1000)}`,
|
|
125
|
+
isoTime: () => `,"time":"${new Date(Date.now()).toISOString()}"`,
|
|
126
|
+
nullTime: () => "",
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=stdSerializers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdSerializers.js","sourceRoot":"","sources":["../src/stdSerializers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uDAAuD;AACvD,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,cAAc,CAC7B,KAAc,EACd,OAAyB,EAAE;IAE3B,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAA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AAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC;YAClC,CAAC,CAAC,IAAI;QACP,OAAO,EACN,OAAO,UAAU,KAAK,UAAU;YAC/B,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC;YACtC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC;KAClC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAIvB;IACH,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC;IACrC,GAAG,EAAE,gBAAgB;IACrB,GAAG,EAAE,iBAAiB;CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAKzB;IACH,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW,IAAI,CAAC,GAAG,EAAE,EAAE;IACxC,QAAQ,EAAE,GAAG,EAAE,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,EAAE;IAC1D,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE,GAAG;IAChE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE;CAClB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a log line is turned into JSON without ever losing it.
|
|
3
|
+
*
|
|
4
|
+
* A bare `JSON.stringify(entry)` throws on a circular reference or a BigInt,
|
|
5
|
+
* and a throw there costs the whole line — every field of it, on every
|
|
6
|
+
* channel. Circular payloads are ordinary (an ORM model with a back-reference,
|
|
7
|
+
* an HTTP client error carrying its request), so the line that explains a
|
|
8
|
+
* failure is the one most likely to vanish.
|
|
9
|
+
*
|
|
10
|
+
* pino's answer, mirrored: `JSON.stringify` first, because it is fast and
|
|
11
|
+
* exact; when it throws, the field is written again by a bounded walker that
|
|
12
|
+
* prints a cycle as `"[Circular]"`, a BigInt as a number, anything deeper than
|
|
13
|
+
* `depthLimit` as `"[Object]"` / `"[Array]"`, and stops after `edgeLimit`
|
|
14
|
+
* entries. Each top-level field falls back on its own, so one bad field does
|
|
15
|
+
* not degrade the others.
|
|
16
|
+
*/
|
|
17
|
+
export interface StringifyLimits {
|
|
18
|
+
/** How deep the fallback walks before writing `"[Object]"`. Default 5. */
|
|
19
|
+
depthLimit: number;
|
|
20
|
+
/** How many entries of one object or array the fallback writes. Default 100. */
|
|
21
|
+
edgeLimit: number;
|
|
22
|
+
}
|
|
23
|
+
export declare const DEFAULT_STRINGIFY_LIMITS: StringifyLimits;
|
|
24
|
+
/** Whether a configured limit is one the walker can honour. */
|
|
25
|
+
export declare function isStringifyLimit(value: unknown): value is number;
|
|
26
|
+
/**
|
|
27
|
+
* One JSON object, never throwing. Keys whose value is `undefined` or a
|
|
28
|
+
* function are left out, as `JSON.stringify` leaves them out.
|
|
29
|
+
*/
|
|
30
|
+
export declare function stringifyRecord(record: Record<string, unknown>, limits?: StringifyLimits): string;
|
|
31
|
+
/** One value, never throwing; `undefined` when JSON would omit it. */
|
|
32
|
+
export declare function stringifyValue(value: unknown, limits?: StringifyLimits): string | undefined;
|
|
33
|
+
//# sourceMappingURL=stringify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringify.d.ts","sourceRoot":"","sources":["../src/stringify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,WAAW,eAAe;IAC/B,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,wBAAwB,EAAE,eAGtC,CAAC;AAKF,+DAA+D;AAC/D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,GAAE,eAA0C,GAChD,MAAM,CAcR;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAC7B,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,eAA0C,GAChD,MAAM,GAAG,SAAS,CAUpB"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a log line is turned into JSON without ever losing it.
|
|
3
|
+
*
|
|
4
|
+
* A bare `JSON.stringify(entry)` throws on a circular reference or a BigInt,
|
|
5
|
+
* and a throw there costs the whole line — every field of it, on every
|
|
6
|
+
* channel. Circular payloads are ordinary (an ORM model with a back-reference,
|
|
7
|
+
* an HTTP client error carrying its request), so the line that explains a
|
|
8
|
+
* failure is the one most likely to vanish.
|
|
9
|
+
*
|
|
10
|
+
* pino's answer, mirrored: `JSON.stringify` first, because it is fast and
|
|
11
|
+
* exact; when it throws, the field is written again by a bounded walker that
|
|
12
|
+
* prints a cycle as `"[Circular]"`, a BigInt as a number, anything deeper than
|
|
13
|
+
* `depthLimit` as `"[Object]"` / `"[Array]"`, and stops after `edgeLimit`
|
|
14
|
+
* entries. Each top-level field falls back on its own, so one bad field does
|
|
15
|
+
* not degrade the others.
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_STRINGIFY_LIMITS = {
|
|
18
|
+
depthLimit: 5,
|
|
19
|
+
edgeLimit: 100,
|
|
20
|
+
};
|
|
21
|
+
const UNSERIALIZABLE = '"[unable to serialize, circular reference is too complex to analyze]"';
|
|
22
|
+
/** Whether a configured limit is one the walker can honour. */
|
|
23
|
+
export function isStringifyLimit(value) {
|
|
24
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One JSON object, never throwing. Keys whose value is `undefined` or a
|
|
28
|
+
* function are left out, as `JSON.stringify` leaves them out.
|
|
29
|
+
*/
|
|
30
|
+
export function stringifyRecord(record, limits = DEFAULT_STRINGIFY_LIMITS) {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.stringify(record);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Field by field, so the fallback's limits count from each field and a
|
|
36
|
+
// field that cannot be written at all is the only one that says so.
|
|
37
|
+
let out = "";
|
|
38
|
+
for (const key of Object.keys(record)) {
|
|
39
|
+
const value = stringifyValue(readField(record, key), limits);
|
|
40
|
+
if (value === undefined)
|
|
41
|
+
continue;
|
|
42
|
+
out += `${out === "" ? "" : ","}${JSON.stringify(key)}:${value}`;
|
|
43
|
+
}
|
|
44
|
+
return `{${out}}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** One value, never throwing; `undefined` when JSON would omit it. */
|
|
48
|
+
export function stringifyValue(value, limits = DEFAULT_STRINGIFY_LIMITS) {
|
|
49
|
+
try {
|
|
50
|
+
return JSON.stringify(value);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
try {
|
|
54
|
+
return walk("", value, [], limits);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return UNSERIALIZABLE;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** A getter that throws is a value that cannot be written, not a lost line. */
|
|
62
|
+
function readField(record, key) {
|
|
63
|
+
try {
|
|
64
|
+
return Reflect.get(record, key);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return "[unreadable]";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function hasToJSON(value) {
|
|
71
|
+
return "toJSON" in value && typeof value.toJSON === "function";
|
|
72
|
+
}
|
|
73
|
+
function itemCount(count) {
|
|
74
|
+
return count === 1 ? "1 item" : `${count} items`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The bounded fallback. `stack` holds the objects on the current path, so a
|
|
78
|
+
* value shared by two branches is written twice and only a real cycle is cut.
|
|
79
|
+
*/
|
|
80
|
+
function walk(key, input, stack, limits) {
|
|
81
|
+
let value = input;
|
|
82
|
+
if (typeof value === "object" && value !== null && hasToJSON(value)) {
|
|
83
|
+
value = value.toJSON(key);
|
|
84
|
+
}
|
|
85
|
+
switch (typeof value) {
|
|
86
|
+
case "string":
|
|
87
|
+
return JSON.stringify(value);
|
|
88
|
+
case "number":
|
|
89
|
+
return Number.isFinite(value) ? String(value) : "null";
|
|
90
|
+
case "boolean":
|
|
91
|
+
return value ? "true" : "false";
|
|
92
|
+
case "bigint":
|
|
93
|
+
return String(value);
|
|
94
|
+
case "object": {
|
|
95
|
+
if (value === null)
|
|
96
|
+
return "null";
|
|
97
|
+
if (stack.includes(value))
|
|
98
|
+
return '"[Circular]"';
|
|
99
|
+
if (Array.isArray(value))
|
|
100
|
+
return walkArray(value, stack, limits);
|
|
101
|
+
return walkObject(value, stack, limits);
|
|
102
|
+
}
|
|
103
|
+
default:
|
|
104
|
+
// undefined, function, symbol: omitted, as JSON omits them.
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function walkArray(value, stack, limits) {
|
|
109
|
+
if (value.length === 0)
|
|
110
|
+
return "[]";
|
|
111
|
+
if (stack.length + 1 > limits.depthLimit)
|
|
112
|
+
return '"[Array]"';
|
|
113
|
+
stack.push(value);
|
|
114
|
+
const shown = Math.min(value.length, limits.edgeLimit);
|
|
115
|
+
const parts = [];
|
|
116
|
+
for (let i = 0; i < shown; i++) {
|
|
117
|
+
parts.push(walk(String(i), value[i], stack, limits) ?? "null");
|
|
118
|
+
}
|
|
119
|
+
if (value.length > shown) {
|
|
120
|
+
parts.push(JSON.stringify(`... ${itemCount(value.length - shown)} not stringified`));
|
|
121
|
+
}
|
|
122
|
+
stack.pop();
|
|
123
|
+
return `[${parts.join(",")}]`;
|
|
124
|
+
}
|
|
125
|
+
function walkObject(value, stack, limits) {
|
|
126
|
+
const keys = Object.keys(value);
|
|
127
|
+
if (keys.length === 0)
|
|
128
|
+
return "{}";
|
|
129
|
+
if (stack.length + 1 > limits.depthLimit)
|
|
130
|
+
return '"[Object]"';
|
|
131
|
+
stack.push(value);
|
|
132
|
+
const shown = Math.min(keys.length, limits.edgeLimit);
|
|
133
|
+
const parts = [];
|
|
134
|
+
for (let i = 0; i < shown; i++) {
|
|
135
|
+
const key = keys[i];
|
|
136
|
+
if (key === undefined)
|
|
137
|
+
continue;
|
|
138
|
+
const written = walk(key, readField(value, key), stack, limits);
|
|
139
|
+
if (written !== undefined)
|
|
140
|
+
parts.push(`${JSON.stringify(key)}:${written}`);
|
|
141
|
+
}
|
|
142
|
+
if (keys.length > shown) {
|
|
143
|
+
parts.push(`"...":${JSON.stringify(`${itemCount(keys.length - shown)} not stringified`)}`);
|
|
144
|
+
}
|
|
145
|
+
stack.pop();
|
|
146
|
+
return `{${parts.join(",")}}`;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=stringify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringify.js","sourceRoot":"","sources":["../src/stringify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AASH,MAAM,CAAC,MAAM,wBAAwB,GAAoB;IACxD,UAAU,EAAE,CAAC;IACb,SAAS,EAAE,GAAG;CACd,CAAC;AAEF,MAAM,cAAc,GACnB,uEAAuE,CAAC;AAEzE,+DAA+D;AAC/D,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC9C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,MAA+B,EAC/B,SAA0B,wBAAwB;IAElD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACR,uEAAuE;Q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KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IACtD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,GAAG,KAAK,SAAS;YAAE,SAAS;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAChE,IAAI,OAAO,KAAK,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;QACzB,KAAK,CAAC,IAAI,CACT,SAAS,IAAI,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAC9E,CAAC;IACH,CAAC;IACD,KAAK,CAAC,GAAG,EAAE,CAAC;IACZ,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAC/B,CAAC"}
|
package/dist/targets.d.ts
CHANGED
|
@@ -13,22 +13,35 @@
|
|
|
13
13
|
* DESCRIPTION that {@link channelsFromTargets} turns into a channel. The config
|
|
14
14
|
* a migrating app already wrote keeps working; what it drives is ours.
|
|
15
15
|
*/
|
|
16
|
-
import type { LogChannel, LogLevelWithSilent } from "./types.js";
|
|
17
|
-
/**
|
|
16
|
+
import type { LogChannel, LogConfig, LogLevelWithSilent } from "./types.js";
|
|
17
|
+
/**
|
|
18
|
+
* One transport entry (AdonisJS `TransportTargetOptions`).
|
|
19
|
+
*
|
|
20
|
+
* `target` names `pino-pretty` or `pino/file`, or is a {@link LogChannel}:
|
|
21
|
+
* a destination spectrum has no built-in channel for is plugged in that way,
|
|
22
|
+
* with the target's own level.
|
|
23
|
+
*/
|
|
18
24
|
export interface TransportTargetOptions {
|
|
19
|
-
target: string;
|
|
25
|
+
target: string | LogChannel;
|
|
20
26
|
options?: Record<string, unknown>;
|
|
21
27
|
level?: LogLevelWithSilent | string;
|
|
22
28
|
}
|
|
23
29
|
/** Options `targets.file()` accepts. `destination` is a path, or an fd. */
|
|
24
30
|
export interface FileTargetOptions {
|
|
25
31
|
destination?: string | number;
|
|
32
|
+
/** `false` starts the file over instead of appending. Default true. */
|
|
33
|
+
append?: boolean;
|
|
26
34
|
maxSizeBytes?: number;
|
|
27
35
|
maxFiles?: number;
|
|
36
|
+
maxBufferBytes?: number;
|
|
28
37
|
[key: string]: unknown;
|
|
29
38
|
}
|
|
30
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Options `targets.pretty()` accepts. `destination` (1 or 2) sends every
|
|
41
|
+
* level to that stream; pino-pretty's formatting options are not read.
|
|
42
|
+
*/
|
|
31
43
|
export interface PrettyTargetOptions {
|
|
44
|
+
destination?: number;
|
|
32
45
|
[key: string]: unknown;
|
|
33
46
|
}
|
|
34
47
|
/** Builds the targets array conditionally. */
|
|
@@ -52,9 +65,9 @@ export declare const targets: (() => Targets) & {
|
|
|
52
65
|
* Turn transport targets into the channels spectrum actually writes through.
|
|
53
66
|
*
|
|
54
67
|
* `pino-pretty` is the human-readable console; `pino/file` writes JSON — to a
|
|
55
|
-
* file when `destination` is a path, and to
|
|
56
|
-
*
|
|
57
|
-
*
|
|
68
|
+
* file when `destination` is a path, and to that descriptor when it is one:
|
|
69
|
+
* `destination: 1` is stdout, which a containerised app ships to its log
|
|
70
|
+
* collector.
|
|
58
71
|
*
|
|
59
72
|
* A target with no level of its own inherits `inheritedLevel`, the level of the
|
|
60
73
|
* logger it belongs to — upstream's `defineConfig` fills the same gap, by
|
|
@@ -62,5 +75,14 @@ export declare const targets: (() => Targets) & {
|
|
|
62
75
|
* the caller's config object alone.
|
|
63
76
|
*/
|
|
64
77
|
export declare function channelsFromTargets(list: readonly TransportTargetOptions[], inheritedLevel?: LogLevelWithSilent | string): LogChannel[];
|
|
78
|
+
/** The channel a logger's `destination` option names. */
|
|
79
|
+
export declare function destinationChannel(destination: unknown): LogChannel;
|
|
80
|
+
/**
|
|
81
|
+
* The channels a config's `destination` or `transport` describe, or
|
|
82
|
+
* `undefined` when it declares neither. `destination` wins over `transport`,
|
|
83
|
+
* as upstream; a transport is either a `targets` list or one
|
|
84
|
+
* `{ target, options }`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function channelsFromConfig(config: Pick<LogConfig, "destination" | "transport">, level: LogLevelWithSilent | string | undefined): LogChannel[] | undefined;
|
|
65
87
|
export {};
|
|
66
88
|
//# 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;
|
|
1
|
+
{"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../src/targets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,OAAO,KAAK,EAEX,UAAU,EACV,SAAS,EAET,kBAAkB,EAClB,MAAM,YAAY,CAAC;AAOpB;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACtC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,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,W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