@rife/logger 0.0.6-beta.10 → 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.
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ "../../node_modules/.pnpm/real-require@0.2.0/node_modules/real-require/src/index.js" (module1) {
4
+ const realImport = new Function('modulePath', 'return import(modulePath)');
5
+ function realRequire(modulePath) {
6
+ if ('function' == typeof __non_webpack__require__) return __non_webpack__require__(modulePath);
7
+ return require(modulePath);
8
+ }
9
+ module1.exports = {
10
+ realImport,
11
+ realRequire
12
+ };
13
+ },
14
+ "../../node_modules/.pnpm/thread-stream@4.0.0/node_modules/thread-stream/lib/indexes.js" (module1) {
15
+ "use strict";
16
+ const WRITE_INDEX = 4;
17
+ const READ_INDEX = 8;
18
+ module1.exports = {
19
+ WRITE_INDEX,
20
+ READ_INDEX
21
+ };
22
+ },
23
+ "../../node_modules/.pnpm/thread-stream@4.0.0/node_modules/thread-stream/lib/wait.js" (module1) {
24
+ "use strict";
25
+ const WAIT_MS = 10000;
26
+ function wait(state, index, expected, timeout, done) {
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);
36
+ };
37
+ check();
38
+ }
39
+ function waitDiff(state, index, expected, timeout, done) {
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);
49
+ };
50
+ check();
51
+ }
52
+ module1.exports = {
53
+ wait,
54
+ waitDiff
55
+ };
56
+ },
57
+ worker_threads (module1) {
58
+ "use strict";
59
+ module1.exports = require("worker_threads");
60
+ }
61
+ };
62
+ var __webpack_module_cache__ = {};
63
+ function __webpack_require__(moduleId) {
64
+ var cachedModule = __webpack_module_cache__[moduleId];
65
+ if (void 0 !== cachedModule) return cachedModule.exports;
66
+ var module1 = __webpack_module_cache__[moduleId] = {
67
+ exports: {}
68
+ };
69
+ __webpack_modules__[moduleId](module1, module1.exports, __webpack_require__);
70
+ return module1.exports;
71
+ }
72
+ var __webpack_exports__ = {};
73
+ (()=>{
74
+ "use strict";
75
+ const { realImport, realRequire } = __webpack_require__("../../node_modules/.pnpm/real-require@0.2.0/node_modules/real-require/src/index.js");
76
+ const { workerData, parentPort } = __webpack_require__("worker_threads");
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");
79
+ const { dataBuf, filename, stateBuf } = workerData;
80
+ let destination;
81
+ const state = new Int32Array(stateBuf);
82
+ const data = Buffer.from(dataBuf);
83
+ const keepAlive = setInterval(()=>{}, 3600000);
84
+ async function start() {
85
+ let worker;
86
+ try {
87
+ worker = await realImport(filename);
88
+ } catch (error) {
89
+ if (('ENOTDIR' === error.code || 'ERR_MODULE_NOT_FOUND' === error.code) && filename.startsWith('file://')) worker = realRequire(decodeURIComponent(filename.replace('file://', '')));
90
+ else if (void 0 === error.code || 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING' === error.code) try {
91
+ worker = realRequire(decodeURIComponent(filename.replace('win32' === process.platform ? 'file:///' : 'file://', '')));
92
+ } catch {
93
+ throw error;
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
+ }
103
+ else throw error;
104
+ }
105
+ if ('object' == typeof worker) worker = worker.default;
106
+ if ('object' == typeof worker) worker = worker.default;
107
+ destination = await worker(workerData.workerData);
108
+ destination.on('error', function(err) {
109
+ Atomics.store(state, WRITE_INDEX, -2);
110
+ Atomics.notify(state, WRITE_INDEX);
111
+ Atomics.store(state, READ_INDEX, -2);
112
+ Atomics.notify(state, READ_INDEX);
113
+ parentPort.postMessage({
114
+ code: 'ERROR',
115
+ err
116
+ });
117
+ });
118
+ destination.on('close', function() {
119
+ const end = Atomics.load(state, WRITE_INDEX);
120
+ Atomics.store(state, READ_INDEX, end);
121
+ Atomics.notify(state, READ_INDEX);
122
+ clearInterval(keepAlive);
123
+ setImmediate(()=>{
124
+ process.exit(0);
125
+ });
126
+ });
127
+ }
128
+ start().then(function() {
129
+ parentPort.postMessage({
130
+ code: 'READY'
131
+ });
132
+ process.nextTick(run);
133
+ });
134
+ function run() {
135
+ const current = Atomics.load(state, READ_INDEX);
136
+ const end = Atomics.load(state, WRITE_INDEX);
137
+ if (end === current) return void (end === data.length ? waitDiff(state, READ_INDEX, end, 1 / 0, run) : waitDiff(state, WRITE_INDEX, end, 1 / 0, run));
138
+ if (-1 === end) return void destination.end();
139
+ const toWrite = data.toString('utf8', current, end);
140
+ const res = destination.write(toWrite);
141
+ if (res) {
142
+ Atomics.store(state, READ_INDEX, end);
143
+ Atomics.notify(state, READ_INDEX);
144
+ setImmediate(run);
145
+ } else destination.once('drain', function() {
146
+ Atomics.store(state, READ_INDEX, end);
147
+ Atomics.notify(state, READ_INDEX);
148
+ run();
149
+ });
150
+ }
151
+ process.on('unhandledRejection', function(err) {
152
+ parentPort.postMessage({
153
+ code: 'ERROR',
154
+ err
155
+ });
156
+ process.exit(1);
157
+ });
158
+ process.on('uncaughtException', function(err) {
159
+ parentPort.postMessage({
160
+ code: 'ERROR',
161
+ err
162
+ });
163
+ process.exit(1);
164
+ });
165
+ process.once('exit', (exitCode)=>{
166
+ if (0 !== exitCode) return void process.exit(exitCode);
167
+ if (destination?.writableNeedDrain && !destination?.writableEnded) parentPort.postMessage({
168
+ code: 'WARNING',
169
+ err: new Error('ThreadStream: process exited before destination stream was drained. this may indicate that the destination stream try to write to a another missing stream')
170
+ });
171
+ process.exit(0);
172
+ });
173
+ })();
174
+ module.exports = __webpack_exports__;
package/dist/cjs/test.cjs CHANGED
@@ -18,11 +18,6 @@ const log = logger.child({
18
18
  }, {
19
19
  msgPrefix: '[123] '
20
20
  });
21
- log.info(2);
22
- log.info({
23
- c: 1,
24
- name: '========'
25
- }, 'name overide');
26
21
  log.error(new Error('cause', {
27
22
  cause: new Error('789')
28
23
  }));
@@ -30,7 +25,16 @@ log.error({
30
25
  error: new Error('error data'),
31
26
  data: 2
32
27
  });
33
- for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
28
+ log.info({
29
+ c: 1,
30
+ name: '========'
31
+ }, 'name overide');
32
+ (0, external_trace_cjs_namespaceObject.runInTrace)({
33
+ traceId: (0, external_trace_cjs_namespaceObject.genTraceId)()
34
+ }, ()=>{
35
+ log.info(1);
36
+ });
37
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
34
38
  Object.defineProperty(exports, '__esModule', {
35
39
  value: true
36
40
  });
@@ -13,7 +13,7 @@ var __webpack_require__ = {};
13
13
  })();
14
14
  (()=>{
15
15
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
17
  value: 'Module'
18
18
  });
19
19
  Object.defineProperty(exports1, '__esModule', {
@@ -24,8 +24,8 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- getTraceId: ()=>getTraceId,
28
27
  runInTrace: ()=>runInTrace,
28
+ getTraceId: ()=>getTraceId,
29
29
  genTraceId: ()=>genTraceId
30
30
  });
31
31
  const external_async_hooks_namespaceObject = require("async_hooks");
@@ -42,11 +42,11 @@ function getTraceId() {
42
42
  exports.genTraceId = __webpack_exports__.genTraceId;
43
43
  exports.getTraceId = __webpack_exports__.getTraceId;
44
44
  exports.runInTrace = __webpack_exports__.runInTrace;
45
- for(var __webpack_i__ in __webpack_exports__)if (-1 === [
45
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
46
46
  "genTraceId",
47
47
  "getTraceId",
48
48
  "runInTrace"
49
- ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
49
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
50
50
  Object.defineProperty(exports, '__esModule', {
51
51
  value: true
52
52
  });
@@ -1,8 +1,8 @@
1
1
  import 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
- import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
3
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
4
4
  import path from "path";
5
- var common_filename = __webpack_fileURLToPath__(import.meta.url);
5
+ var common_filename = __rspack_fileURLToPath(import.meta.url);
6
6
  const isEsm = '.mjs' === path.extname(common_filename);
7
7
  const isCjs = !isEsm;
8
8
  export { isCjs, isEsm };
@@ -1,18 +1,42 @@
1
1
  import 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
- import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
4
- import { dirname as __webpack_dirname__ } from "node:path";
3
+ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
4
+ import { dirname as __rspack_dirname } from "node:path";
5
+ import * as __rspack_external_pino_std_serializers_719fa64c from "pino-std-serializers";
5
6
  import path from "path";
6
7
  import pino from "pino";
7
- import { isEsm } from "../common.mjs";
8
- import { getTraceId } from "../trace.mjs";
9
- var pino_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
8
+ import { genTraceId, getTraceId, runInTrace } from "../trace.mjs";
9
+ var __webpack_modules__ = {
10
+ "pino-std-serializers" (module) {
11
+ module.exports = __rspack_external_pino_std_serializers_719fa64c;
12
+ }
13
+ };
14
+ var __webpack_module_cache__ = {};
15
+ function __webpack_require__(moduleId) {
16
+ var cachedModule = __webpack_module_cache__[moduleId];
17
+ if (void 0 !== cachedModule) return cachedModule.exports;
18
+ var module = __webpack_module_cache__[moduleId] = {
19
+ exports: {}
20
+ };
21
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
22
+ return module.exports;
23
+ }
24
+ var pino_filename = __rspack_fileURLToPath(import.meta.url);
25
+ var pino_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
10
26
  function getPinoConfig() {
11
27
  const targets = [];
12
- if ('undefined' != typeof PINO_RSPACK_PLUGIN) globalThis.__bundlerPathsOverrides = {
28
+ const rotate = `./rotate${path.extname(pino_filename)}`;
29
+ targets.push({
30
+ level: 'debug',
31
+ target: rotate,
32
+ options: {
33
+ path: './logs/'
34
+ }
35
+ });
36
+ if ("u" > typeof __isNodeSingleFileBundle || "u" > typeof __isVite || global?.__remix_devServerHooks || 'development' !== process.env.NODE_ENV) globalThis.__bundlerPathsOverrides = {
13
37
  'pino-pretty': path.join(pino_dirname, './worker/pino-pretty.cjs'),
14
38
  'pino-worker': path.join(pino_dirname, './worker/pino-worker.cjs'),
15
- './rotate.cjs': path.join(pino_dirname, './worker/pino-rotate.cjs'),
39
+ [rotate]: path.join(pino_dirname, './worker/pino-rotate.cjs'),
16
40
  'pino/file': path.join(pino_dirname, './worker/pino-file.cjs'),
17
41
  'thread-stream-worker': path.join(pino_dirname, './worker/thread-stream.cjs'),
18
42
  ...globalThis.__bundlerPathsOverrides
@@ -25,27 +49,24 @@ function getPinoConfig() {
25
49
  messageKey: 'message'
26
50
  }
27
51
  });
28
- targets.push({
29
- level: 'debug',
30
- target: `./rotate${isEsm ? '.mjs' : '.cjs'}`,
31
- options: {
32
- path: './logs/'
33
- }
34
- });
35
52
  const config = {
36
53
  transport: {
37
54
  targets
38
55
  },
39
56
  mixin (data) {
57
+ const traceId = data?.traceId;
58
+ delete data.traceId;
40
59
  delete data.level;
41
60
  delete data.time;
42
61
  delete data.pid;
43
62
  delete data.name;
44
63
  delete data.hostname;
45
- if (!data?.traceId) return {
64
+ if (!traceId) return {
46
65
  traceId: getTraceId()
47
66
  };
48
- return {};
67
+ return {
68
+ traceId
69
+ };
49
70
  }
50
71
  };
51
72
  return config;
@@ -64,4 +85,36 @@ function createLogger() {
64
85
  logger
65
86
  };
66
87
  }
67
- export { createLogger };
88
+ function useExpress(logger, format) {
89
+ const serializers = __webpack_require__("pino-std-serializers");
90
+ const mapHttpRequest = serializers.mapHttpRequest;
91
+ const mapHttpResponse = serializers.mapHttpResponse || serializers.default.mapHttpResponse;
92
+ const startTime = Symbol();
93
+ return (req, res, next)=>{
94
+ const response = res;
95
+ response[startTime] = response[startTime] || Date.now();
96
+ const traceId = req.headers['trace-id'] || genTraceId();
97
+ const onComplete = ()=>{
98
+ res.removeListener('close', onComplete);
99
+ res.removeListener('finish', onComplete);
100
+ res.removeListener('error', onComplete);
101
+ const duration = Date.now() - response[startTime];
102
+ const serializedRequest = mapHttpRequest(req).req;
103
+ const serializedResponse = mapHttpResponse(res).res;
104
+ const msg = `${serializedRequest.method} ${serializedRequest.url}`;
105
+ const info = {
106
+ duration,
107
+ request: serializedRequest,
108
+ response: serializedResponse
109
+ };
110
+ logger.info(format?.(info) || info, msg);
111
+ };
112
+ res.on('close', onComplete);
113
+ res.on('finish', onComplete);
114
+ res.on('error', onComplete);
115
+ runInTrace({
116
+ traceId
117
+ }, next);
118
+ };
119
+ }
120
+ export { createLogger, useExpress };
@@ -1,9 +1,9 @@
1
1
  import 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
- import * as __WEBPACK_EXTERNAL_MODULE_rotating_file_stream_66c5ea63__ from "rotating-file-stream";
3
+ import * as __rspack_external_rotating_file_stream_66c5ea63 from "rotating-file-stream";
4
4
  var __webpack_modules__ = {
5
- "rotating-file-stream": function(module) {
6
- module.exports = __WEBPACK_EXTERNAL_MODULE_rotating_file_stream_66c5ea63__;
5
+ "rotating-file-stream" (module) {
6
+ module.exports = __rspack_external_rotating_file_stream_66c5ea63;
7
7
  }
8
8
  };
9
9
  var __webpack_module_cache__ = {};