@decohere/scribe-pino 0.0.1-dev.13 → 0.0.1-dev.131
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/LICENSE +15 -0
- package/commonjs/src/index.js +1 -2
- package/commonjs/src/pino.adapater.js +130 -7
- package/commonjs/src/pino.recipe.js +106 -0
- package/commonjs/src/pino.transport-guard.js +68 -0
- package/commonjs/src/scribe-pino.js +132 -31
- package/es6/src/index.js +1 -2
- package/es6/src/pino.adapater.js +131 -8
- package/es6/src/pino.recipe.js +96 -0
- package/es6/src/pino.transport-guard.js +61 -0
- package/es6/src/scribe-pino.js +114 -28
- package/package.json +25 -4
- package/types/src/index.d.ts +1 -0
- package/types/src/pino.adapater.d.ts +8 -0
- package/types/src/pino.recipe.d.ts +45 -0
- package/types/src/pino.transport-guard.d.ts +10 -0
- package/types/src/scribe-pino.d.ts +56 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Typesmiths
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/commonjs/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
_export_star(require("./pino.adapater.js"), exports);
|
|
6
|
+
_export_star(require("./pino.recipe.js"), exports);
|
|
6
7
|
_export_star(require("./scribe-pino.js"), exports);
|
|
7
8
|
function _export_star(from, to) {
|
|
8
9
|
Object.keys(from).forEach(function(k) {
|
|
@@ -17,5 +18,3 @@ function _export_star(from, to) {
|
|
|
17
18
|
});
|
|
18
19
|
return from;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9ob21lL3J1bm5lci93b3JrL2RlY29oZXJlL2RlY29oZXJlL3Byb2plY3RzL3NjcmliZS9zY3JpYmUtcGluby9zcmMvaW5kZXgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0ICogZnJvbSBcIi4vcGluby5hZGFwYXRlci5qc1wiO1xuZXhwb3J0ICogZnJvbSBcIi4vc2NyaWJlLXBpbm8uanNcIjtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O3FCQUFjO3FCQUNBIn0=
|
|
@@ -19,6 +19,8 @@ class PinoAdapter extends _scribe.LogAdapter {
|
|
|
19
19
|
_pino;
|
|
20
20
|
options;
|
|
21
21
|
stream;
|
|
22
|
+
disposed = false;
|
|
23
|
+
retired = false;
|
|
22
24
|
constructor(options, stream){
|
|
23
25
|
super();
|
|
24
26
|
this.options = options;
|
|
@@ -48,18 +50,136 @@ class PinoAdapter extends _scribe.LogAdapter {
|
|
|
48
50
|
return logger;
|
|
49
51
|
}
|
|
50
52
|
flush(cb) {
|
|
53
|
+
if (this.retired || !this._pino) {
|
|
54
|
+
cb?.();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
51
57
|
this._pino.flush(cb);
|
|
52
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Immediately stop accepting writes into the destination (ThreadStream).
|
|
61
|
+
* Does not wait for flush — use `stop()` for async drain after retire.
|
|
62
|
+
*/ retire() {
|
|
63
|
+
if (this.retired) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.retired = true;
|
|
67
|
+
const guarded = this.stream;
|
|
68
|
+
if (typeof guarded?.retire === "function") {
|
|
69
|
+
guarded.retire("adapter retired");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
destroyDestination(this.stream);
|
|
73
|
+
}
|
|
74
|
+
async [Symbol.asyncDispose]() {
|
|
75
|
+
if (this.disposed) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.disposed = true;
|
|
79
|
+
if (!this.retired) {
|
|
80
|
+
const dest = this.stream;
|
|
81
|
+
if (dest != null && typeof dest.end === "function") {
|
|
82
|
+
// pino.transport() is a ThreadStream: pino.flush() → Atomics.waitAsync can
|
|
83
|
+
// hang forever after concurrent writes. end() flushSyncs then signals
|
|
84
|
+
// finish/close (it does not accept a Node Writable callback).
|
|
85
|
+
await endDestination(dest);
|
|
86
|
+
} else if (this._pino) {
|
|
87
|
+
await new Promise((resolve, reject)=>{
|
|
88
|
+
try {
|
|
89
|
+
this._pino.flush((err)=>{
|
|
90
|
+
if (err != null) {
|
|
91
|
+
reject(err);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
resolve();
|
|
95
|
+
});
|
|
96
|
+
} catch (err) {
|
|
97
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Mark dead after graceful end (or immediately if already force-retired).
|
|
103
|
+
this.retire();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function destroyDestination(stream) {
|
|
107
|
+
const destroyable = stream;
|
|
108
|
+
if (typeof destroyable?.destroy === "function") {
|
|
109
|
+
try {
|
|
110
|
+
destroyable.destroy();
|
|
111
|
+
} catch {
|
|
112
|
+
// already dead
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Drain a pino destination.
|
|
118
|
+
*
|
|
119
|
+
* Node `Writable.end(cb)` invokes `cb`. `pino.transport()` returns a
|
|
120
|
+
* ThreadStream whose `end()` takes no callback and signals via `finish`/`close`
|
|
121
|
+
* instead — waiting only on `end(cb)` hangs forever and blocks Flux HMR.
|
|
122
|
+
*/ function endDestination(stream) {
|
|
123
|
+
if (typeof stream.end !== "function") {
|
|
124
|
+
return Promise.resolve();
|
|
125
|
+
}
|
|
126
|
+
if (stream.destroyed || stream.closed || stream.writableFinished) {
|
|
127
|
+
return Promise.resolve();
|
|
128
|
+
}
|
|
129
|
+
return new Promise((resolve, reject)=>{
|
|
130
|
+
let settled = false;
|
|
131
|
+
const settle = (err)=>{
|
|
132
|
+
if (settled) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
settled = true;
|
|
136
|
+
stream.off?.("finish", onFinish);
|
|
137
|
+
stream.off?.("close", onClose);
|
|
138
|
+
stream.off?.("error", onError);
|
|
139
|
+
if (err != null) {
|
|
140
|
+
reject(err);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
resolve();
|
|
144
|
+
};
|
|
145
|
+
const onFinish = ()=>settle();
|
|
146
|
+
const onClose = ()=>settle();
|
|
147
|
+
const onError = (err)=>{
|
|
148
|
+
// ThreadStream may emit error then close during teardown; closed = done.
|
|
149
|
+
if (stream.destroyed || stream.closed) {
|
|
150
|
+
settle();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
settle(err);
|
|
154
|
+
};
|
|
155
|
+
stream.once?.("finish", onFinish);
|
|
156
|
+
stream.once?.("close", onClose);
|
|
157
|
+
stream.once?.("error", onError);
|
|
158
|
+
try {
|
|
159
|
+
stream.end((err)=>settle(err));
|
|
160
|
+
} catch (err) {
|
|
161
|
+
settle(err instanceof Error ? err : new Error(String(err)));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// ThreadStream.end() is a no-op when already destroyed (no events).
|
|
165
|
+
if (stream.destroyed || stream.closed || stream.writableFinished) {
|
|
166
|
+
settle();
|
|
167
|
+
}
|
|
168
|
+
});
|
|
53
169
|
}
|
|
54
170
|
function logMethod(args, method) {
|
|
55
171
|
let message = args.at(0);
|
|
56
172
|
const data = args.at(1);
|
|
173
|
+
if (message instanceof Error) {
|
|
174
|
+
method.call(this, {
|
|
175
|
+
err: message
|
|
176
|
+
}, (0, _scribe.formatError)(message));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
57
179
|
if (data instanceof Error) {
|
|
58
180
|
message = {
|
|
59
181
|
msg: message,
|
|
60
|
-
|
|
61
|
-
error: data
|
|
62
|
-
}
|
|
182
|
+
error: data
|
|
63
183
|
};
|
|
64
184
|
} else if (typeof data === "object") {
|
|
65
185
|
message = {
|
|
@@ -74,15 +194,18 @@ function logMethod(args, method) {
|
|
|
74
194
|
}
|
|
75
195
|
method.call(this, message);
|
|
76
196
|
}
|
|
77
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Add Scribe's logger members to a Pino logger. `spawn` is Pino's own `child`:
|
|
199
|
+
* a Pino child inherits its parent's members through the prototype, so
|
|
200
|
+
* `logger.child` would be the parent's override.
|
|
201
|
+
*/ function pinoMix(logger, spawn = logger.child) {
|
|
78
202
|
return Object.assign(logger, {
|
|
79
203
|
get currentLevel () {
|
|
80
204
|
return logger.level;
|
|
81
205
|
},
|
|
82
206
|
get logLevels () {
|
|
83
207
|
return logger.levels.values;
|
|
84
|
-
}
|
|
208
|
+
},
|
|
209
|
+
child: (fields)=>pinoMix(spawn.call(logger, fields), spawn)
|
|
85
210
|
});
|
|
86
211
|
}
|
|
87
|
-
|
|
88
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9u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BQU9hLE9BQU9DLE1BQU0sQ0FBMEJkLFFBQVE7UUFDckQsSUFBSWUsZ0JBQWU7WUFDbEIsT0FBT2YsT0FBT1gsS0FBSztRQUNwQjtRQUNBLElBQUkyQixhQUFZO1lBQ2YsT0FBT2hCLE9BQU9pQixNQUFNLENBQUNDLE1BQU07UUFDNUI7SUFDRDtBQUNEIn0=
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "pinoRecipe", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return pinoRecipe;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _system = require("@decohere/core/system");
|
|
12
|
+
const DEFAULT_ROLL_SIZE = "10m";
|
|
13
|
+
const DEFAULT_ROLL_FREQUENCY = "daily";
|
|
14
|
+
const DEFAULT_ROLL_KEEP = 14;
|
|
15
|
+
const ENV_LOG_FILE = "SCRIBE_LOG_FILE";
|
|
16
|
+
const ENV_LOG_SIZE = "SCRIBE_LOG_SIZE";
|
|
17
|
+
const ENV_LOG_FREQUENCY = "SCRIBE_LOG_FREQUENCY";
|
|
18
|
+
const ENV_LOG_KEEP = "SCRIBE_LOG_KEEP";
|
|
19
|
+
function currentEnvironment() {
|
|
20
|
+
return process.env.NODE_ENV === _system.Environments.production ? _system.Environments.production : _system.Environments.development;
|
|
21
|
+
}
|
|
22
|
+
function isEnabled(when, environment) {
|
|
23
|
+
return (when ?? "development") === "always" || environment === _system.Environments.development;
|
|
24
|
+
}
|
|
25
|
+
function envString(name) {
|
|
26
|
+
const value = process.env[name]?.trim();
|
|
27
|
+
return value ? value : undefined;
|
|
28
|
+
}
|
|
29
|
+
function envFrequency() {
|
|
30
|
+
const raw = envString(ENV_LOG_FREQUENCY);
|
|
31
|
+
if (raw == null) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (/^\d+$/.test(raw)) {
|
|
35
|
+
return Number(raw);
|
|
36
|
+
}
|
|
37
|
+
return raw;
|
|
38
|
+
}
|
|
39
|
+
function envKeep() {
|
|
40
|
+
const raw = envString(ENV_LOG_KEEP);
|
|
41
|
+
if (raw == null) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const keep = Number(raw);
|
|
45
|
+
return Number.isFinite(keep) && keep >= 0 ? keep : undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Resolve roll options. `SCRIBE_LOG_FILE` overrides `file` so ops can redirect
|
|
49
|
+
* without touching app code. Size / frequency / keep: explicit > env > default.
|
|
50
|
+
*/ function resolveRoll(options) {
|
|
51
|
+
return {
|
|
52
|
+
file: envString(ENV_LOG_FILE) ?? options.file,
|
|
53
|
+
size: options.size ?? envString(ENV_LOG_SIZE) ?? DEFAULT_ROLL_SIZE,
|
|
54
|
+
frequency: options.frequency ?? envFrequency() ?? DEFAULT_ROLL_FREQUENCY,
|
|
55
|
+
keep: options.keep ?? envKeep() ?? DEFAULT_ROLL_KEEP,
|
|
56
|
+
mkdir: options.mkdir ?? true,
|
|
57
|
+
symlink: options.symlink ?? false
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function prettyTarget(options) {
|
|
61
|
+
return {
|
|
62
|
+
target: "pino-pretty",
|
|
63
|
+
options: {
|
|
64
|
+
colorize: options.colorize ?? true
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function rollTarget(options) {
|
|
69
|
+
const roll = resolveRoll(options);
|
|
70
|
+
return {
|
|
71
|
+
target: "pino-roll",
|
|
72
|
+
options: {
|
|
73
|
+
file: roll.file,
|
|
74
|
+
mkdir: roll.mkdir,
|
|
75
|
+
size: roll.size,
|
|
76
|
+
frequency: roll.frequency,
|
|
77
|
+
limit: {
|
|
78
|
+
count: roll.keep
|
|
79
|
+
},
|
|
80
|
+
symlink: roll.symlink
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function transport(plan, environment = currentEnvironment()) {
|
|
85
|
+
const targets = [];
|
|
86
|
+
if (plan.pretty && isEnabled(plan.pretty.when, environment)) {
|
|
87
|
+
targets.push(prettyTarget(plan.pretty));
|
|
88
|
+
}
|
|
89
|
+
if (plan.roll && isEnabled(plan.roll.when, environment)) {
|
|
90
|
+
targets.push(rollTarget(plan.roll));
|
|
91
|
+
}
|
|
92
|
+
if (targets.length === 0) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
if (targets.length === 1) {
|
|
96
|
+
return targets[0];
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
targets
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const pinoRecipe = {
|
|
103
|
+
transport,
|
|
104
|
+
currentEnvironment,
|
|
105
|
+
resolveRoll
|
|
106
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "guardTransport", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return guardTransport;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function guardTransport(transport) {
|
|
12
|
+
const stream = transport;
|
|
13
|
+
let retired = false;
|
|
14
|
+
let reported = false;
|
|
15
|
+
const retire = (reason = "retired")=>{
|
|
16
|
+
if (retired) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
retired = true;
|
|
20
|
+
if (!reported) {
|
|
21
|
+
reported = true;
|
|
22
|
+
process.stderr.write(`[scribe-pino] transport retired: ${reason}\n`);
|
|
23
|
+
}
|
|
24
|
+
if (typeof stream.destroy === "function") {
|
|
25
|
+
try {
|
|
26
|
+
stream.destroy();
|
|
27
|
+
} catch {
|
|
28
|
+
// already dead
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
if (typeof stream.on === "function") {
|
|
33
|
+
stream.on("error", (err)=>{
|
|
34
|
+
retire(err?.message ?? String(err));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (typeof stream.write === "function") {
|
|
38
|
+
const originalWrite = stream.write.bind(stream);
|
|
39
|
+
stream.write = (chunk, encodingOrCb, cb)=>{
|
|
40
|
+
if (retired) {
|
|
41
|
+
completeWrite(encodingOrCb, cb);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return originalWrite(chunk, encodingOrCb, cb);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
retire(err instanceof Error ? err.message : String(err));
|
|
48
|
+
completeWrite(encodingOrCb, cb);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
Object.defineProperty(stream, "retired", {
|
|
54
|
+
get: ()=>retired,
|
|
55
|
+
enumerable: true
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(stream, "retire", {
|
|
58
|
+
value: retire,
|
|
59
|
+
enumerable: true
|
|
60
|
+
});
|
|
61
|
+
return stream;
|
|
62
|
+
}
|
|
63
|
+
function completeWrite(encodingOrCb, cb) {
|
|
64
|
+
const done = typeof encodingOrCb === "function" ? encodingOrCb : typeof cb === "function" ? cb : undefined;
|
|
65
|
+
if (typeof done === "function") {
|
|
66
|
+
done();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -2,16 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get PinoExtensions () {
|
|
8
13
|
return PinoExtensions;
|
|
14
|
+
},
|
|
15
|
+
get guardTransport () {
|
|
16
|
+
return _pinotransportguard.guardTransport;
|
|
17
|
+
},
|
|
18
|
+
get pinoTransport () {
|
|
19
|
+
return pinoTransport;
|
|
9
20
|
}
|
|
10
21
|
});
|
|
11
|
-
const _extensibility = require("@decohere/
|
|
12
|
-
const _system = require("@decohere/
|
|
22
|
+
const _extensibility = require("@decohere/core/extensibility");
|
|
23
|
+
const _system = require("@decohere/core/system");
|
|
13
24
|
const _scribe = require("@decohere/scribe");
|
|
25
|
+
const _pino = /*#__PURE__*/ _interop_require_default(require("pino"));
|
|
14
26
|
const _pinoadapater = require("./pino.adapater.js");
|
|
27
|
+
const _pinorecipe = require("./pino.recipe.js");
|
|
28
|
+
const _pinotransportguard = require("./pino.transport-guard.js");
|
|
29
|
+
function _interop_require_default(obj) {
|
|
30
|
+
return obj && obj.__esModule ? obj : {
|
|
31
|
+
default: obj
|
|
32
|
+
};
|
|
33
|
+
}
|
|
15
34
|
function _ts_decorate(decorators, target, key, desc) {
|
|
16
35
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
17
36
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -23,27 +42,32 @@ function _ts_metadata(k, v) {
|
|
|
23
42
|
}
|
|
24
43
|
class PinoExtensions {
|
|
25
44
|
static withPino(factory, config, logLevel) {
|
|
26
|
-
return configureScribe(factory, {
|
|
45
|
+
return configureScribe(factory, logLevel != null ? {
|
|
27
46
|
logLevel
|
|
28
|
-
}, config);
|
|
47
|
+
} : undefined, config);
|
|
29
48
|
}
|
|
30
|
-
static withPinoPretty(factory,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
static withPinoPretty(factory, logLevelOrOptions) {
|
|
50
|
+
const pretty = parsePrettyArg(logLevelOrOptions);
|
|
51
|
+
return attachRecipe(factory, {
|
|
52
|
+
pretty,
|
|
53
|
+
logLevel: pretty.logLevel
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
static withPinoRoll(factory, options) {
|
|
57
|
+
return attachRecipe(factory, {
|
|
58
|
+
roll: options,
|
|
59
|
+
logLevel: options.logLevel
|
|
60
|
+
});
|
|
39
61
|
}
|
|
40
62
|
static withPinoCustom(factory, options) {
|
|
41
|
-
const { scribe, transports } = options;
|
|
63
|
+
const { scribe, transports } = options ?? {};
|
|
42
64
|
return configureScribe(factory, scribe, transports);
|
|
43
65
|
}
|
|
44
66
|
}
|
|
45
67
|
_ts_decorate([
|
|
46
|
-
(0, _extensibility.extension)(_scribe.scribe
|
|
68
|
+
(0, _extensibility.extension)(_scribe.scribe, {
|
|
69
|
+
static: true
|
|
70
|
+
}),
|
|
47
71
|
_ts_metadata("design:type", Function),
|
|
48
72
|
_ts_metadata("design:paramtypes", [
|
|
49
73
|
typeof _scribe.scribe === "undefined" ? Object : _scribe.scribe,
|
|
@@ -53,7 +77,9 @@ _ts_decorate([
|
|
|
53
77
|
_ts_metadata("design:returntype", void 0)
|
|
54
78
|
], PinoExtensions, "withPino", null);
|
|
55
79
|
_ts_decorate([
|
|
56
|
-
(0, _extensibility.extension)(_scribe.scribe
|
|
80
|
+
(0, _extensibility.extension)(_scribe.scribe, {
|
|
81
|
+
static: true
|
|
82
|
+
}),
|
|
57
83
|
_ts_metadata("design:type", Function),
|
|
58
84
|
_ts_metadata("design:paramtypes", [
|
|
59
85
|
typeof _scribe.scribe === "undefined" ? Object : _scribe.scribe,
|
|
@@ -62,7 +88,20 @@ _ts_decorate([
|
|
|
62
88
|
_ts_metadata("design:returntype", void 0)
|
|
63
89
|
], PinoExtensions, "withPinoPretty", null);
|
|
64
90
|
_ts_decorate([
|
|
65
|
-
(0, _extensibility.extension)(_scribe.scribe
|
|
91
|
+
(0, _extensibility.extension)(_scribe.scribe, {
|
|
92
|
+
static: true
|
|
93
|
+
}),
|
|
94
|
+
_ts_metadata("design:type", Function),
|
|
95
|
+
_ts_metadata("design:paramtypes", [
|
|
96
|
+
typeof _scribe.scribe === "undefined" ? Object : _scribe.scribe,
|
|
97
|
+
typeof PinoRollRecipeOptions === "undefined" ? Object : PinoRollRecipeOptions
|
|
98
|
+
]),
|
|
99
|
+
_ts_metadata("design:returntype", void 0)
|
|
100
|
+
], PinoExtensions, "withPinoRoll", null);
|
|
101
|
+
_ts_decorate([
|
|
102
|
+
(0, _extensibility.extension)(_scribe.scribe, {
|
|
103
|
+
static: true
|
|
104
|
+
}),
|
|
66
105
|
_ts_metadata("design:type", Function),
|
|
67
106
|
_ts_metadata("design:paramtypes", [
|
|
68
107
|
typeof _scribe.scribe === "undefined" ? Object : _scribe.scribe,
|
|
@@ -70,23 +109,85 @@ _ts_decorate([
|
|
|
70
109
|
]),
|
|
71
110
|
_ts_metadata("design:returntype", void 0)
|
|
72
111
|
], PinoExtensions, "withPinoCustom", null);
|
|
112
|
+
function parsePrettyArg(logLevelOrOptions) {
|
|
113
|
+
if (logLevelOrOptions == null) {
|
|
114
|
+
return {};
|
|
115
|
+
}
|
|
116
|
+
if (typeof logLevelOrOptions === "string") {
|
|
117
|
+
return {
|
|
118
|
+
logLevel: logLevelOrOptions
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return logLevelOrOptions;
|
|
122
|
+
}
|
|
123
|
+
function attachRecipe(factory, plan) {
|
|
124
|
+
const loggerFactory = applyRecipe(factory, plan);
|
|
125
|
+
const chain = {
|
|
126
|
+
withPinoPretty (logLevelOrOptions) {
|
|
127
|
+
const pretty = parsePrettyArg(logLevelOrOptions);
|
|
128
|
+
return attachRecipe(factory, {
|
|
129
|
+
...plan,
|
|
130
|
+
pretty: {
|
|
131
|
+
...plan.pretty,
|
|
132
|
+
...pretty
|
|
133
|
+
},
|
|
134
|
+
logLevel: pretty.logLevel ?? plan.logLevel
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
withPinoRoll (options) {
|
|
138
|
+
return attachRecipe(factory, {
|
|
139
|
+
...plan,
|
|
140
|
+
roll: options,
|
|
141
|
+
logLevel: options.logLevel ?? plan.logLevel
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return Object.assign(loggerFactory, chain, {
|
|
146
|
+
and: chain
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Guard a worker transport so failures (roll EEXIST, worker exit) neither
|
|
151
|
+
* crash the process nor spam stderr on every subsequent log write.
|
|
152
|
+
*/ function createSafeTransport(options) {
|
|
153
|
+
return (0, _pinotransportguard.guardTransport)(_pino.default.transport(options));
|
|
154
|
+
}
|
|
155
|
+
function adapterForTransport(transport) {
|
|
156
|
+
if (transport == null) {
|
|
157
|
+
return new _pinoadapater.PinoAdapter({});
|
|
158
|
+
}
|
|
159
|
+
return new _pinoadapater.PinoAdapter({}, createSafeTransport(transport));
|
|
160
|
+
}
|
|
161
|
+
function applyRecipe(factory, plan) {
|
|
162
|
+
const adapter = adapterForTransport(_pinorecipe.pinoRecipe.transport(plan));
|
|
163
|
+
// Omit logLevel when unset so mergeDefaults can read LOG_LEVEL / SCRIBE_LOG_LEVEL.
|
|
164
|
+
return factory.configure({
|
|
165
|
+
options: plan.logLevel != null ? {
|
|
166
|
+
logLevel: plan.logLevel
|
|
167
|
+
} : {},
|
|
168
|
+
adapter
|
|
169
|
+
});
|
|
170
|
+
}
|
|
73
171
|
function configureScribe(factory, options, config) {
|
|
74
172
|
const environment = process.env.NODE_ENV ?? _system.DefaultEnvironment;
|
|
75
|
-
const configs = Array.isArray(config) ? config : [
|
|
173
|
+
const configs = (Array.isArray(config) ? config : config != null ? [
|
|
76
174
|
config
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
if (transports.length > 1) {
|
|
175
|
+
] : []).filter((item)=>item.environment == null || item.environment === environment);
|
|
176
|
+
if (configs.length > 1) {
|
|
80
177
|
throw new _scribe.LoggingConfigurationError(`There should only be one configuration per environment for logging`);
|
|
81
178
|
}
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
transport
|
|
85
|
-
});
|
|
179
|
+
const adapter = adapterForTransport(configs.at(0)?.transports);
|
|
180
|
+
// Do not force DefaultLogLevel — that would shadow env resolution in mergeDefaults.
|
|
86
181
|
return factory.configure({
|
|
87
|
-
options,
|
|
182
|
+
options: options ?? {},
|
|
88
183
|
adapter
|
|
89
184
|
});
|
|
90
185
|
}
|
|
91
|
-
|
|
92
|
-
|
|
186
|
+
/** @deprecated Use {@link guardTransport} — kept for callers/tests from the silence-only era. */ function silenceErrors(transport) {
|
|
187
|
+
return (0, _pinotransportguard.guardTransport)(transport);
|
|
188
|
+
}
|
|
189
|
+
const pinoTransport = {
|
|
190
|
+
createSafeTransport,
|
|
191
|
+
guardTransport: _pinotransportguard.guardTransport,
|
|
192
|
+
silenceErrors
|
|
193
|
+
};
|
package/es6/src/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export * from "./pino.adapater.js";
|
|
2
|
+
export * from "./pino.recipe.js";
|
|
2
3
|
export * from "./scribe-pino.js";
|
|
3
|
-
|
|
4
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9ob21lL3J1bm5lci93b3JrL2RlY29oZXJlL2RlY29oZXJlL3Byb2plY3RzL3NjcmliZS9zY3JpYmUtcGluby9zcmMvaW5kZXgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0ICogZnJvbSBcIi4vcGluby5hZGFwYXRlci5qc1wiO1xuZXhwb3J0ICogZnJvbSBcIi4vc2NyaWJlLXBpbm8uanNcIjtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHFCQUFxQjtBQUNuQyxjQUFjLG1CQUFtQiJ9
|