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