@rife/logger 0.0.6-beta.15 → 0.0.6-beta.17
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/dist/cjs/common.cjs +9 -5
- package/dist/cjs/env.cjs +13 -9
- package/dist/cjs/index.cjs +9 -5
- package/dist/cjs/pino/index.cjs +34 -13
- package/dist/cjs/pino/rotate.cjs +12 -8
- package/dist/cjs/pino/worker/pino-file.cjs +198 -106
- package/dist/cjs/pino/worker/pino-pretty.cjs +47 -43
- package/dist/cjs/pino/worker/pino-rotate.cjs +12 -8
- package/dist/cjs/pino/worker/pino-worker.cjs +198 -106
- package/dist/cjs/pino/worker/thread-stream.cjs +107 -13
- package/dist/cjs/trace.cjs +11 -7
- package/dist/esm/common.mjs +2 -2
- package/dist/esm/pino/index.mjs +33 -16
- package/dist/esm/pino/rotate.mjs +2 -2
- package/dist/esm/pino/worker/pino-file.cjs +198 -106
- package/dist/esm/pino/worker/pino-pretty.cjs +47 -43
- package/dist/esm/pino/worker/pino-rotate.cjs +12 -8
- package/dist/esm/pino/worker/pino-worker.cjs +198 -106
- package/dist/esm/pino/worker/thread-stream.cjs +107 -13
- package/dist/worker/pino-file.cjs +198 -106
- package/dist/worker/pino-pretty.cjs +47 -43
- package/dist/worker/pino-rotate.cjs +12 -8
- package/dist/worker/pino-worker.cjs +198 -106
- package/dist/worker/thread-stream.cjs +107 -13
- package/package.json +3 -3
- package/src/pino/index.ts +16 -6
- package/dist/cjs/worker/index.cjs +0 -5
- package/dist/esm/worker/index.mjs +0 -1
- package/src/worker/index.ts +0 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
"../../node_modules/.pnpm/real-require@0.
|
|
3
|
+
"../../node_modules/.pnpm/real-require@1.0.0/node_modules/real-require/src/index.js" (module1) {
|
|
4
4
|
const realImport = new Function('modulePath', 'return import(modulePath)');
|
|
5
5
|
function realRequire(modulePath) {
|
|
6
6
|
if ('function' == typeof __non_webpack__require__) return __non_webpack__require__(modulePath);
|
|
@@ -11,16 +11,18 @@ var __webpack_modules__ = {
|
|
|
11
11
|
realRequire
|
|
12
12
|
};
|
|
13
13
|
},
|
|
14
|
-
"../../node_modules/.pnpm/thread-stream@4.
|
|
14
|
+
"../../node_modules/.pnpm/thread-stream@4.2.0/node_modules/thread-stream/lib/indexes.js" (module1) {
|
|
15
15
|
"use strict";
|
|
16
|
+
const SEQ_INDEX = 2;
|
|
16
17
|
const WRITE_INDEX = 4;
|
|
17
18
|
const READ_INDEX = 8;
|
|
18
19
|
module1.exports = {
|
|
19
20
|
WRITE_INDEX,
|
|
20
|
-
READ_INDEX
|
|
21
|
+
READ_INDEX,
|
|
22
|
+
SEQ_INDEX
|
|
21
23
|
};
|
|
22
24
|
},
|
|
23
|
-
"../../node_modules/.pnpm/thread-stream@4.
|
|
25
|
+
"../../node_modules/.pnpm/thread-stream@4.2.0/node_modules/thread-stream/lib/wait.js" (module1) {
|
|
24
26
|
"use strict";
|
|
25
27
|
const WAIT_MS = 10000;
|
|
26
28
|
function wait(state, index, expected, timeout, done) {
|
|
@@ -44,7 +46,10 @@ var __webpack_modules__ = {
|
|
|
44
46
|
if (max !== 1 / 0 && Date.now() > max) return void done(null, 'timed-out');
|
|
45
47
|
const remaining = max === 1 / 0 ? WAIT_MS : Math.min(WAIT_MS, Math.max(1, max - Date.now()));
|
|
46
48
|
const result = Atomics.waitAsync(state, index, expected, remaining);
|
|
47
|
-
if (result.async) result.value.then(
|
|
49
|
+
if (result.async) result.value.then((res)=>{
|
|
50
|
+
if ('ok' === res) return void done(null, 'ok');
|
|
51
|
+
check();
|
|
52
|
+
});
|
|
48
53
|
else setImmediate(check);
|
|
49
54
|
};
|
|
50
55
|
check();
|
|
@@ -54,6 +59,10 @@ var __webpack_modules__ = {
|
|
|
54
59
|
waitDiff
|
|
55
60
|
};
|
|
56
61
|
},
|
|
62
|
+
string_decoder (module1) {
|
|
63
|
+
"use strict";
|
|
64
|
+
module1.exports = require("string_decoder");
|
|
65
|
+
},
|
|
57
66
|
worker_threads (module1) {
|
|
58
67
|
"use strict";
|
|
59
68
|
module1.exports = require("worker_threads");
|
|
@@ -72,15 +81,81 @@ function __webpack_require__(moduleId) {
|
|
|
72
81
|
var __webpack_exports__ = {};
|
|
73
82
|
(()=>{
|
|
74
83
|
"use strict";
|
|
75
|
-
const { realImport, realRequire } = __webpack_require__("../../node_modules/.pnpm/real-require@0.
|
|
84
|
+
const { realImport, realRequire } = __webpack_require__("../../node_modules/.pnpm/real-require@1.0.0/node_modules/real-require/src/index.js");
|
|
76
85
|
const { workerData, parentPort } = __webpack_require__("worker_threads");
|
|
77
|
-
const {
|
|
78
|
-
const {
|
|
86
|
+
const { StringDecoder } = __webpack_require__("string_decoder");
|
|
87
|
+
const { WRITE_INDEX, READ_INDEX, SEQ_INDEX } = __webpack_require__("../../node_modules/.pnpm/thread-stream@4.2.0/node_modules/thread-stream/lib/indexes.js");
|
|
88
|
+
const { waitDiff } = __webpack_require__("../../node_modules/.pnpm/thread-stream@4.2.0/node_modules/thread-stream/lib/wait.js");
|
|
79
89
|
const { dataBuf, filename, stateBuf } = workerData;
|
|
80
90
|
let destination;
|
|
91
|
+
const flushQueue = [];
|
|
92
|
+
let flushing = false;
|
|
81
93
|
const state = new Int32Array(stateBuf);
|
|
82
94
|
const data = Buffer.from(dataBuf);
|
|
95
|
+
const decoder = new StringDecoder('utf8');
|
|
83
96
|
const keepAlive = setInterval(()=>{}, 3600000);
|
|
97
|
+
function onParentPortMessage(msg) {
|
|
98
|
+
if (!msg || 'FLUSH' !== msg.code || 'thread-stream' !== msg.context) return;
|
|
99
|
+
flushQueue.push(msg.id);
|
|
100
|
+
processFlushQueue();
|
|
101
|
+
}
|
|
102
|
+
function processFlushQueue() {
|
|
103
|
+
if (flushing || !destination) return;
|
|
104
|
+
const id = flushQueue.shift();
|
|
105
|
+
if (void 0 === id) return;
|
|
106
|
+
flushing = true;
|
|
107
|
+
flushDestination((err)=>{
|
|
108
|
+
flushing = false;
|
|
109
|
+
if (err) return void parentPort.postMessage({
|
|
110
|
+
code: 'ERROR',
|
|
111
|
+
err
|
|
112
|
+
});
|
|
113
|
+
parentPort.postMessage({
|
|
114
|
+
code: 'FLUSHED',
|
|
115
|
+
context: 'thread-stream',
|
|
116
|
+
id
|
|
117
|
+
});
|
|
118
|
+
processFlushQueue();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function flushDestination(cb) {
|
|
122
|
+
if ('function' == typeof destination?.flush) {
|
|
123
|
+
if (0 === destination.flush.length) {
|
|
124
|
+
try {
|
|
125
|
+
const result = destination.flush();
|
|
126
|
+
if (result && 'function' == typeof result.then) result.then(()=>cb(), cb);
|
|
127
|
+
else cb();
|
|
128
|
+
} catch (err) {
|
|
129
|
+
cb(err);
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
let done = false;
|
|
134
|
+
const onDone = (err)=>{
|
|
135
|
+
if (done) return;
|
|
136
|
+
done = true;
|
|
137
|
+
cb(err);
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
const result = destination.flush(onDone);
|
|
141
|
+
if (result && 'function' == typeof result.then) result.then(()=>onDone(), onDone);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
onDone(err);
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if ('function' == typeof destination?.flushSync) {
|
|
148
|
+
try {
|
|
149
|
+
destination.flushSync();
|
|
150
|
+
cb();
|
|
151
|
+
} catch (err) {
|
|
152
|
+
cb(err);
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (destination?.writableNeedDrain && !destination?.writableEnded) return void destination.once('drain', cb);
|
|
157
|
+
cb();
|
|
158
|
+
}
|
|
84
159
|
async function start() {
|
|
85
160
|
let worker;
|
|
86
161
|
try {
|
|
@@ -124,19 +199,38 @@ var __webpack_exports__ = {};
|
|
|
124
199
|
process.exit(0);
|
|
125
200
|
});
|
|
126
201
|
});
|
|
202
|
+
processFlushQueue();
|
|
127
203
|
}
|
|
128
204
|
start().then(function() {
|
|
205
|
+
parentPort.on('message', onParentPortMessage);
|
|
129
206
|
parentPort.postMessage({
|
|
130
207
|
code: 'READY'
|
|
131
208
|
});
|
|
132
209
|
process.nextTick(run);
|
|
133
210
|
});
|
|
211
|
+
function readState() {
|
|
212
|
+
while(true){
|
|
213
|
+
const seq = Atomics.load(state, SEQ_INDEX);
|
|
214
|
+
if ((1 & seq) !== 0) continue;
|
|
215
|
+
const current = Atomics.load(state, READ_INDEX);
|
|
216
|
+
const end = Atomics.load(state, WRITE_INDEX);
|
|
217
|
+
if (seq === Atomics.load(state, SEQ_INDEX)) return {
|
|
218
|
+
current,
|
|
219
|
+
end,
|
|
220
|
+
seq
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
134
224
|
function run() {
|
|
135
|
-
const current =
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
225
|
+
const { current, end, seq } = readState();
|
|
226
|
+
if (end === current) return void waitDiff(state, SEQ_INDEX, seq, 1 / 0, run);
|
|
227
|
+
if (-1 === end) {
|
|
228
|
+
const remaining = decoder.end();
|
|
229
|
+
if (remaining.length > 0) destination.write(remaining);
|
|
230
|
+
destination.end();
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const toWrite = decoder.write(data.subarray(current, end));
|
|
140
234
|
const res = destination.write(toWrite);
|
|
141
235
|
if (res) {
|
|
142
236
|
Atomics.store(state, READ_INDEX, end);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rife/logger",
|
|
3
|
-
"version": "0.0.6-beta.
|
|
3
|
+
"version": "0.0.6-beta.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"thread-stream": "^4.0.0",
|
|
47
|
-
"@rife/cli": "0.0.6-beta.
|
|
48
|
-
"@rife/plugin-rstack": "0.0.1-beta.
|
|
47
|
+
"@rife/cli": "0.0.6-beta.24",
|
|
48
|
+
"@rife/plugin-rstack": "0.0.1-beta.24"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"dev": "rife dev",
|
package/src/pino/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
|
|
3
2
|
import pino from 'pino';
|
|
4
3
|
|
|
5
4
|
export { pino };
|
|
@@ -66,7 +65,6 @@ function getPinoConfig() {
|
|
|
66
65
|
delete data.level;
|
|
67
66
|
delete data.time;
|
|
68
67
|
delete data.pid;
|
|
69
|
-
delete data.name;
|
|
70
68
|
delete data.hostname;
|
|
71
69
|
if (!traceId) {
|
|
72
70
|
return { traceId: getTraceId() };
|
|
@@ -75,17 +73,29 @@ function getPinoConfig() {
|
|
|
75
73
|
},
|
|
76
74
|
// cloudfare worker 需要自己实现输出
|
|
77
75
|
browser: {
|
|
76
|
+
// https://github.com/pinojs/pino/blob/main/docs/browser.md
|
|
77
|
+
serialize: true,
|
|
78
78
|
write: (o: any) => {
|
|
79
79
|
// https://github.com/pinojs/pino/blob/main/docs/api.md#level-1
|
|
80
|
-
const {
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
const { fn, time, level, ...rest } = o;
|
|
81
|
+
const clone = { ...o };
|
|
82
|
+
if (fn) {
|
|
83
|
+
rest.message = rest.message ? `[${fn}] ${rest.message}` : `[${fn}]`;
|
|
83
84
|
}
|
|
84
85
|
if (!rest.traceId) {
|
|
85
86
|
rest.traceId = getTraceId();
|
|
87
|
+
clone.traceId = getTraceId();
|
|
86
88
|
}
|
|
87
89
|
if (level >= 50) {
|
|
88
|
-
|
|
90
|
+
const keys = ['fn', 'time', 'level'];
|
|
91
|
+
keys.forEach(k => delete clone[k]);
|
|
92
|
+
if (clone.msg) {
|
|
93
|
+
clone.msg = `${clone.name || 'Error'}: ${clone.msg}`;
|
|
94
|
+
if (fn) {
|
|
95
|
+
clone.msg = `[${fn}] ${clone.msg}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
console.error(clone);
|
|
89
99
|
} else if (level >= 40) {
|
|
90
100
|
console.warn(rest);
|
|
91
101
|
} else {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
package/src/worker/index.ts
DELETED