@decohere/scribe-pino 0.0.1-dev.126 → 0.0.1-dev.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commonjs/src/index.js +2 -1
- package/commonjs/src/pino.adapater.js +7 -130
- package/commonjs/src/scribe-pino.js +31 -132
- package/es6/src/index.js +2 -1
- package/es6/src/pino.adapater.js +8 -131
- package/es6/src/scribe-pino.js +28 -114
- package/package.json +4 -25
- package/types/src/index.d.ts +0 -1
- package/types/src/pino.adapater.d.ts +0 -8
- package/types/src/scribe-pino.d.ts +8 -56
- package/LICENSE +0 -15
- package/commonjs/src/pino.recipe.js +0 -106
- package/commonjs/src/pino.transport-guard.js +0 -68
- package/es6/src/pino.recipe.js +0 -96
- package/es6/src/pino.transport-guard.js +0 -61
- package/types/src/pino.recipe.d.ts +0 -45
- package/types/src/pino.transport-guard.d.ts +0 -10
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wrap a pino worker transport so a dead ThreadStream cannot spam or crash.
|
|
3
|
-
* On first error / write throw: report once, destroy, no-op further writes.
|
|
4
|
-
*/ export function guardTransport(transport) {
|
|
5
|
-
const stream = transport;
|
|
6
|
-
let retired = false;
|
|
7
|
-
let reported = false;
|
|
8
|
-
const retire = (reason = "retired")=>{
|
|
9
|
-
if (retired) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
retired = true;
|
|
13
|
-
if (!reported) {
|
|
14
|
-
reported = true;
|
|
15
|
-
process.stderr.write(`[scribe-pino] transport retired: ${reason}\n`);
|
|
16
|
-
}
|
|
17
|
-
if (typeof stream.destroy === "function") {
|
|
18
|
-
try {
|
|
19
|
-
stream.destroy();
|
|
20
|
-
} catch {
|
|
21
|
-
// already dead
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
if (typeof stream.on === "function") {
|
|
26
|
-
stream.on("error", (err)=>{
|
|
27
|
-
retire(err?.message ?? String(err));
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
if (typeof stream.write === "function") {
|
|
31
|
-
const originalWrite = stream.write.bind(stream);
|
|
32
|
-
stream.write = (chunk, encodingOrCb, cb)=>{
|
|
33
|
-
if (retired) {
|
|
34
|
-
completeWrite(encodingOrCb, cb);
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
return originalWrite(chunk, encodingOrCb, cb);
|
|
39
|
-
} catch (err) {
|
|
40
|
-
retire(err instanceof Error ? err.message : String(err));
|
|
41
|
-
completeWrite(encodingOrCb, cb);
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
Object.defineProperty(stream, "retired", {
|
|
47
|
-
get: ()=>retired,
|
|
48
|
-
enumerable: true
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(stream, "retire", {
|
|
51
|
-
value: retire,
|
|
52
|
-
enumerable: true
|
|
53
|
-
});
|
|
54
|
-
return stream;
|
|
55
|
-
}
|
|
56
|
-
function completeWrite(encodingOrCb, cb) {
|
|
57
|
-
const done = typeof encodingOrCb === "function" ? encodingOrCb : typeof cb === "function" ? cb : undefined;
|
|
58
|
-
if (typeof done === "function") {
|
|
59
|
-
done();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { type Environment } from "@decohere/core/system";
|
|
2
|
-
import type { TransportMultiOptions, TransportSingleOptions } from "pino";
|
|
3
|
-
/** Pretty and roll are local-dev conveniences. Production ships JSON on stdout. */
|
|
4
|
-
export type PinoWhen = "development" | "always";
|
|
5
|
-
export type PinoPrettyRecipeOptions = {
|
|
6
|
-
colorize?: boolean;
|
|
7
|
-
logLevel?: string;
|
|
8
|
-
when?: PinoWhen;
|
|
9
|
-
};
|
|
10
|
-
export type PinoRollRecipeOptions = {
|
|
11
|
-
/** Default roll path. Overridden at runtime by `SCRIBE_LOG_FILE` when set. */
|
|
12
|
-
file: string;
|
|
13
|
-
size?: string;
|
|
14
|
-
frequency?: string | number;
|
|
15
|
-
keep?: number;
|
|
16
|
-
mkdir?: boolean;
|
|
17
|
-
symlink?: boolean;
|
|
18
|
-
logLevel?: string;
|
|
19
|
-
when?: PinoWhen;
|
|
20
|
-
};
|
|
21
|
-
export type PinoRecipePlan = {
|
|
22
|
-
pretty?: PinoPrettyRecipeOptions;
|
|
23
|
-
roll?: PinoRollRecipeOptions;
|
|
24
|
-
logLevel?: string;
|
|
25
|
-
};
|
|
26
|
-
declare function currentEnvironment(): Environment;
|
|
27
|
-
/**
|
|
28
|
-
* Resolve roll options. `SCRIBE_LOG_FILE` overrides `file` so ops can redirect
|
|
29
|
-
* without touching app code. Size / frequency / keep: explicit > env > default.
|
|
30
|
-
*/
|
|
31
|
-
declare function resolveRoll(options: PinoRollRecipeOptions): {
|
|
32
|
-
file: string;
|
|
33
|
-
size: string;
|
|
34
|
-
frequency: string | number;
|
|
35
|
-
keep: number;
|
|
36
|
-
mkdir: boolean;
|
|
37
|
-
symlink: boolean;
|
|
38
|
-
};
|
|
39
|
-
declare function transport(plan: PinoRecipePlan, environment?: Environment): TransportSingleOptions | TransportMultiOptions | undefined;
|
|
40
|
-
export declare const pinoRecipe: {
|
|
41
|
-
transport: typeof transport;
|
|
42
|
-
currentEnvironment: typeof currentEnvironment;
|
|
43
|
-
resolveRoll: typeof resolveRoll;
|
|
44
|
-
};
|
|
45
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { DestinationStream } from "pino";
|
|
2
|
-
export type GuardedTransport = DestinationStream & {
|
|
3
|
-
readonly retired: boolean;
|
|
4
|
-
retire(reason?: string): void;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Wrap a pino worker transport so a dead ThreadStream cannot spam or crash.
|
|
8
|
-
* On first error / write throw: report once, destroy, no-op further writes.
|
|
9
|
-
*/
|
|
10
|
-
export declare function guardTransport(transport: DestinationStream): GuardedTransport;
|