@rife/logger 0.0.6-beta.11 → 0.0.6-beta.12

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.
@@ -1,5 +1,6 @@
1
+ "use strict";
1
2
  var __webpack_modules__ = {
2
- "../../node_modules/.pnpm/real-require@0.2.0/node_modules/real-require/src/index.js": function(module1) {
3
+ "../../node_modules/.pnpm/real-require@0.2.0/node_modules/real-require/src/index.js" (module1) {
3
4
  const realImport = new Function('modulePath', 'return import(modulePath)');
4
5
  function realRequire(modulePath) {
5
6
  if ('function' == typeof __non_webpack__require__) return __non_webpack__require__(modulePath);
@@ -10,7 +11,7 @@ var __webpack_modules__ = {
10
11
  realRequire
11
12
  };
12
13
  },
13
- "../../node_modules/.pnpm/thread-stream@3.1.0/node_modules/thread-stream/lib/indexes.js": function(module1) {
14
+ "../../node_modules/.pnpm/thread-stream@4.0.0/node_modules/thread-stream/lib/indexes.js" (module1) {
14
15
  "use strict";
15
16
  const WRITE_INDEX = 4;
16
17
  const READ_INDEX = 8;
@@ -19,45 +20,41 @@ var __webpack_modules__ = {
19
20
  READ_INDEX
20
21
  };
21
22
  },
22
- "../../node_modules/.pnpm/thread-stream@3.1.0/node_modules/thread-stream/lib/wait.js": function(module1) {
23
+ "../../node_modules/.pnpm/thread-stream@4.0.0/node_modules/thread-stream/lib/wait.js" (module1) {
23
24
  "use strict";
24
- const MAX_TIMEOUT = 1000;
25
+ const WAIT_MS = 10000;
25
26
  function wait(state, index, expected, timeout, done) {
26
- const max = Date.now() + timeout;
27
- let current = Atomics.load(state, index);
28
- if (current === expected) return void done(null, 'ok');
29
- let prior = current;
30
- const check = (backoff)=>{
31
- if (Date.now() > max) done(null, 'timed-out');
32
- else setTimeout(()=>{
33
- prior = current;
34
- current = Atomics.load(state, index);
35
- if (current === prior) check(backoff >= MAX_TIMEOUT ? MAX_TIMEOUT : 2 * backoff);
36
- else current === expected ? done(null, 'ok') : done(null, 'not-equal');
37
- }, backoff);
27
+ const max = timeout === 1 / 0 ? 1 / 0 : Date.now() + timeout;
28
+ const check = ()=>{
29
+ const current = Atomics.load(state, index);
30
+ if (current === expected) return void done(null, 'ok');
31
+ if (max !== 1 / 0 && Date.now() > max) return void done(null, 'timed-out');
32
+ const remaining = max === 1 / 0 ? WAIT_MS : Math.min(WAIT_MS, Math.max(1, max - Date.now()));
33
+ const result = Atomics.waitAsync(state, index, current, remaining);
34
+ if (result.async) result.value.then(check);
35
+ else setImmediate(check);
38
36
  };
39
- check(1);
37
+ check();
40
38
  }
41
39
  function waitDiff(state, index, expected, timeout, done) {
42
- const max = Date.now() + timeout;
43
- let current = Atomics.load(state, index);
44
- if (current !== expected) return void done(null, 'ok');
45
- const check = (backoff)=>{
46
- if (Date.now() > max) done(null, 'timed-out');
47
- else setTimeout(()=>{
48
- current = Atomics.load(state, index);
49
- if (current !== expected) done(null, 'ok');
50
- else check(backoff >= MAX_TIMEOUT ? MAX_TIMEOUT : 2 * backoff);
51
- }, backoff);
40
+ const max = timeout === 1 / 0 ? 1 / 0 : Date.now() + timeout;
41
+ const check = ()=>{
42
+ const current = Atomics.load(state, index);
43
+ if (current !== expected) return void done(null, 'ok');
44
+ if (max !== 1 / 0 && Date.now() > max) return void done(null, 'timed-out');
45
+ const remaining = max === 1 / 0 ? WAIT_MS : Math.min(WAIT_MS, Math.max(1, max - Date.now()));
46
+ const result = Atomics.waitAsync(state, index, expected, remaining);
47
+ if (result.async) result.value.then(check);
48
+ else setImmediate(check);
52
49
  };
53
- check(1);
50
+ check();
54
51
  }
55
52
  module1.exports = {
56
53
  wait,
57
54
  waitDiff
58
55
  };
59
56
  },
60
- worker_threads: function(module1) {
57
+ worker_threads (module1) {
61
58
  "use strict";
62
59
  module1.exports = require("worker_threads");
63
60
  }
@@ -77,21 +74,17 @@ var __webpack_exports__ = {};
77
74
  "use strict";
78
75
  const { realImport, realRequire } = __webpack_require__("../../node_modules/.pnpm/real-require@0.2.0/node_modules/real-require/src/index.js");
79
76
  const { workerData, parentPort } = __webpack_require__("worker_threads");
80
- const { WRITE_INDEX, READ_INDEX } = __webpack_require__("../../node_modules/.pnpm/thread-stream@3.1.0/node_modules/thread-stream/lib/indexes.js");
81
- const { waitDiff } = __webpack_require__("../../node_modules/.pnpm/thread-stream@3.1.0/node_modules/thread-stream/lib/wait.js");
77
+ const { WRITE_INDEX, READ_INDEX } = __webpack_require__("../../node_modules/.pnpm/thread-stream@4.0.0/node_modules/thread-stream/lib/indexes.js");
78
+ const { waitDiff } = __webpack_require__("../../node_modules/.pnpm/thread-stream@4.0.0/node_modules/thread-stream/lib/wait.js");
82
79
  const { dataBuf, filename, stateBuf } = workerData;
83
80
  let destination;
84
81
  const state = new Int32Array(stateBuf);
85
82
  const data = Buffer.from(dataBuf);
83
+ const keepAlive = setInterval(()=>{}, 3600000);
86
84
  async function start() {
87
85
  let worker;
88
86
  try {
89
- if (filename.endsWith('.ts') || filename.endsWith('.cts')) {
90
- if (process[Symbol.for('ts-node.register.instance')]) {
91
- if (process.env.TS_NODE_DEV) realRequire('ts-node-dev');
92
- } else realRequire('ts-node/register');
93
- worker = realRequire(decodeURIComponent(filename.replace('win32' === process.platform ? 'file:///' : 'file://', '')));
94
- } else worker = await realImport(filename);
87
+ worker = await realImport(filename);
95
88
  } catch (error) {
96
89
  if (('ENOTDIR' === error.code || 'ERR_MODULE_NOT_FOUND' === error.code) && filename.startsWith('file://')) worker = realRequire(decodeURIComponent(filename.replace('file://', '')));
97
90
  else if (void 0 === error.code || 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING' === error.code) try {
@@ -99,6 +92,14 @@ var __webpack_exports__ = {};
99
92
  } catch {
100
93
  throw error;
101
94
  }
95
+ else if (filename.endsWith('.ts') || filename.endsWith('.cts')) try {
96
+ if (process[Symbol.for('ts-node.register.instance')]) {
97
+ if (process.env.TS_NODE_DEV) realRequire('ts-node-dev');
98
+ } else realRequire('ts-node/register');
99
+ worker = realRequire(decodeURIComponent(filename.replace('win32' === process.platform ? 'file:///' : 'file://', '')));
100
+ } catch {
101
+ throw error;
102
+ }
102
103
  else throw error;
103
104
  }
104
105
  if ('object' == typeof worker) worker = worker.default;
@@ -118,6 +119,7 @@ var __webpack_exports__ = {};
118
119
  const end = Atomics.load(state, WRITE_INDEX);
119
120
  Atomics.store(state, READ_INDEX, end);
120
121
  Atomics.notify(state, READ_INDEX);
122
+ clearInterval(keepAlive);
121
123
  setImmediate(()=>{
122
124
  process.exit(0);
123
125
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rife/logger",
3
- "version": "0.0.6-beta.11",
3
+ "version": "0.0.6-beta.12",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "./src/index.ts",
@@ -30,14 +30,14 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "pino": "^10.1.0",
33
- "pino-pretty": "^13.1.2",
33
+ "pino-pretty": "^13.1.3",
34
34
  "pino-std-serializers": "^7.0.0",
35
35
  "rotating-file-stream": "^3.2.7"
36
36
  },
37
37
  "devDependencies": {
38
- "thread-stream": "*",
39
- "@rife/cli": "0.0.6-beta.16",
40
- "@rife/plugin-rstack": "0.0.1-beta.15"
38
+ "thread-stream": "^4.0.0",
39
+ "@rife/cli": "0.0.6-beta.20",
40
+ "@rife/plugin-rstack": "0.0.1-beta.17"
41
41
  },
42
42
  "scripts": {
43
43
  "dev": "rife dev",
package/src/pino/index.ts CHANGED
@@ -53,15 +53,17 @@ function getPinoConfig() {
53
53
  mixin(data: any) {
54
54
  // {"level":30,"time":1726065716643,"pid":21968,"hostname":"Win-LH"}
55
55
  // 基础字段不能重复 删除掉
56
+ const traceId = data?.traceId;
57
+ delete data.traceId;
56
58
  delete data.level;
57
59
  delete data.time;
58
60
  delete data.pid;
59
61
  delete data.name;
60
62
  delete data.hostname;
61
- if (!data?.traceId) {
63
+ if (!traceId) {
62
64
  return { traceId: getTraceId() };
63
65
  }
64
- return {};
66
+ return { traceId };
65
67
  },
66
68
  };
67
69
 
package/src/test.ts CHANGED
@@ -2,7 +2,7 @@ process.env.NODE_ENV = 'development';
2
2
  // process.env.NODE_ENV = 'production';
3
3
 
4
4
  import { createLogger } from './pino';
5
- import { genTraceId } from './trace';
5
+ import { genTraceId, runInTrace } from './trace';
6
6
 
7
7
  const { logger } = createLogger();
8
8
 
@@ -16,4 +16,7 @@ const log = logger.child({ name: 'name123', traceId: genTraceId() }, { msgPrefix
16
16
  log.error(new Error('cause', { cause: new Error('789') }));
17
17
  log.error({ error: new Error('error data'), data: 2 });
18
18
  log.info({ c: 1, name: '========' }, 'name overide');
19
- log.info(1);
19
+
20
+ runInTrace({ traceId: genTraceId() }, () => {
21
+ log.info(1);
22
+ });