@abtnode/util 1.8.60 → 1.8.62
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/lib/format-name.js +5 -0
- package/lib/log.js +138 -2
- package/package.json +16 -10
package/lib/log.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const
|
|
3
|
+
const createArchive = require('archiver');
|
|
4
|
+
const fs = require('fs-extra');
|
|
5
|
+
const dayjs = require('dayjs');
|
|
6
|
+
const glob = require('fast-glob');
|
|
4
7
|
const isEqual = require('lodash/isEqual');
|
|
5
8
|
const { Tail } = require('tail');
|
|
6
9
|
const readLastLines = require('read-last-lines');
|
|
@@ -177,12 +180,118 @@ const getLogFiles = async ({ name, node }) => {
|
|
|
177
180
|
return {};
|
|
178
181
|
}
|
|
179
182
|
|
|
180
|
-
return provider.getLogFilesForToday(
|
|
183
|
+
return provider.getLogFilesForToday();
|
|
181
184
|
}
|
|
182
185
|
|
|
183
186
|
return {};
|
|
184
187
|
};
|
|
185
188
|
|
|
189
|
+
const getDownloadLogFilesFromServer = async ({ dates, nodeInfo, node } = {}) => {
|
|
190
|
+
const logDir = path.join(node.dataDirs.logs, '_abtnode');
|
|
191
|
+
|
|
192
|
+
const pm2Log = path.join(logDir, 'pm2.log');
|
|
193
|
+
const pm2LogSrc = path.join(process.env.PM2_HOME, 'pm2.log');
|
|
194
|
+
if (fs.existsSync(pm2LogSrc)) {
|
|
195
|
+
await fs.copy(pm2LogSrc, pm2Log);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const provider = node.getRouterProvider(nodeInfo.routing.provider);
|
|
199
|
+
if (!provider) {
|
|
200
|
+
logger.error('router engine is empty');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const list = [];
|
|
204
|
+
|
|
205
|
+
dates.forEach((d) => {
|
|
206
|
+
// log file created by @abtnode/log
|
|
207
|
+
// log file created by abt-node-log-rotate
|
|
208
|
+
list.push(path.join(logDir, `*-${d}*`));
|
|
209
|
+
|
|
210
|
+
// log file create by router
|
|
211
|
+
const routerLogDir = provider.getLogDir();
|
|
212
|
+
if (routerLogDir) {
|
|
213
|
+
list.push(path.join(routerLogDir, `*-${d}*`));
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// abt-node-daemon console & gateway
|
|
218
|
+
list.push(path.join(logDir, 'daemon.stdout.log*'));
|
|
219
|
+
list.push(path.join(logDir, 'daemon.stderr.log*'));
|
|
220
|
+
list.push(path.join(logDir, 'access.log*'));
|
|
221
|
+
|
|
222
|
+
// abt-node-service console & gateway
|
|
223
|
+
list.push(path.join(logDir, 'service.output.log*'));
|
|
224
|
+
list.push(path.join(logDir, 'service.error.log*'));
|
|
225
|
+
list.push(path.join(logDir, 'service.log*'));
|
|
226
|
+
|
|
227
|
+
// abt-node-db-hub console & backup
|
|
228
|
+
list.push(path.join(logDir, 'db.output.log*'));
|
|
229
|
+
list.push(path.join(logDir, 'db.error.log*'));
|
|
230
|
+
|
|
231
|
+
// abt-node-event-hub console
|
|
232
|
+
list.push(path.join(logDir, 'event.output.log*'));
|
|
233
|
+
list.push(path.join(logDir, 'event.error.log*'));
|
|
234
|
+
|
|
235
|
+
// abt-node-log-rotate console
|
|
236
|
+
list.push(path.join(logDir, 'pm2-logrotate.stdout.log*'));
|
|
237
|
+
list.push(path.join(logDir, 'pm2-logrotate.stderr.log*'));
|
|
238
|
+
|
|
239
|
+
// abt-node-updater console
|
|
240
|
+
list.push(path.join(logDir, 'updater.error.log*'));
|
|
241
|
+
list.push(path.join(logDir, 'updater.output.log*'));
|
|
242
|
+
|
|
243
|
+
// fallback log
|
|
244
|
+
list.push(path.join(logDir, 'stderr.log*'));
|
|
245
|
+
list.push(path.join(logDir, 'stdout.log*'));
|
|
246
|
+
|
|
247
|
+
// router
|
|
248
|
+
list.push(...Object.values(provider.getLogFilesForToday() || {}));
|
|
249
|
+
|
|
250
|
+
// pm2 log
|
|
251
|
+
list.push(pm2Log);
|
|
252
|
+
|
|
253
|
+
return glob(list);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const getDownloadLogFilesFromBlocklet = async ({ dates, blocklet } = {}) => {
|
|
257
|
+
const logDir = path.join(blocklet.env.logsDir);
|
|
258
|
+
|
|
259
|
+
const list = [];
|
|
260
|
+
|
|
261
|
+
dates.forEach((d) => {
|
|
262
|
+
// log file created by @abtnode/log
|
|
263
|
+
// log file created by abt-node-log-rotate
|
|
264
|
+
list.push(path.join(logDir, `*-${d}*`));
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
list.push(path.join(logDir, 'output.log*'));
|
|
268
|
+
list.push(path.join(logDir, 'error.log*'));
|
|
269
|
+
list.push(path.join(logDir, 'access.log*'));
|
|
270
|
+
|
|
271
|
+
return glob(list);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const getDownloadLogFiles = async ({ did, node, days = 1, now } = {}) => {
|
|
275
|
+
const dates = [dayjs(now).format('YYYY-MM-DD')];
|
|
276
|
+
|
|
277
|
+
for (let i = 1; i <= days; i++) {
|
|
278
|
+
dates.unshift(dayjs(now).subtract(i, 'day').format('YYYY-MM-DD'));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const nodeInfo = await node.getNodeInfo();
|
|
282
|
+
|
|
283
|
+
if (nodeInfo.did === did) {
|
|
284
|
+
return getDownloadLogFilesFromServer({ dates, node, nodeInfo });
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const blocklet = await node.getBlocklet({ did, attachRuntimeInfo: false });
|
|
288
|
+
if (!blocklet) {
|
|
289
|
+
throw new Error('blocklet not found');
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return getDownloadLogFilesFromBlocklet({ dates, blocklet });
|
|
293
|
+
};
|
|
294
|
+
|
|
186
295
|
const createStreamLogManager = ({ onLog, onGetLogFiles }) => {
|
|
187
296
|
const store = {}; // Object<name: streamLog>
|
|
188
297
|
|
|
@@ -249,7 +358,34 @@ const createStreamLogManager = ({ onLog, onGetLogFiles }) => {
|
|
|
249
358
|
};
|
|
250
359
|
};
|
|
251
360
|
|
|
361
|
+
const createDownloadLogStream = async ({ node, did, days, now }) => {
|
|
362
|
+
const files = await getDownloadLogFiles({ node, did, days, now });
|
|
363
|
+
|
|
364
|
+
if (!files.length) {
|
|
365
|
+
throw new Error('Log file does not found');
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const cwd = path.dirname(node.dataDirs.logs);
|
|
369
|
+
|
|
370
|
+
const archive = createArchive('zip', { zlib: { level: 9 } });
|
|
371
|
+
files.forEach((x) => {
|
|
372
|
+
archive.file(x, {
|
|
373
|
+
name: x.replace(`${cwd}/logs`, '/logs').replace(`${cwd}`, '/logs').replace('/_abtnode', '/blocklet-server'),
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
archive.rawPipe = archive.pipe.bind(archive);
|
|
378
|
+
archive.pipe = (s) => {
|
|
379
|
+
archive.rawPipe(s);
|
|
380
|
+
archive.finalize();
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
return archive;
|
|
384
|
+
};
|
|
385
|
+
|
|
252
386
|
module.exports = {
|
|
253
387
|
createStreamLogManager,
|
|
254
388
|
getLogFiles,
|
|
389
|
+
getDownloadLogFiles,
|
|
390
|
+
createDownloadLogStream,
|
|
255
391
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.62",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,18 +18,21 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.8.
|
|
22
|
-
"@abtnode/logger": "1.8.
|
|
23
|
-
"@arcblock/jwt": "^1.18.
|
|
24
|
-
"@blocklet/constant": "1.8.
|
|
25
|
-
"@ocap/mcrypto": "1.18.
|
|
26
|
-
"@ocap/util": "1.18.
|
|
27
|
-
"@ocap/wallet": "1.18.
|
|
21
|
+
"@abtnode/constant": "1.8.62",
|
|
22
|
+
"@abtnode/logger": "1.8.62",
|
|
23
|
+
"@arcblock/jwt": "^1.18.36",
|
|
24
|
+
"@blocklet/constant": "1.8.62",
|
|
25
|
+
"@ocap/mcrypto": "1.18.36",
|
|
26
|
+
"@ocap/util": "1.18.36",
|
|
27
|
+
"@ocap/wallet": "1.18.36",
|
|
28
|
+
"archiver": "^5.3.1",
|
|
28
29
|
"axios": "^0.27.2",
|
|
29
30
|
"axios-mock-adapter": "^1.21.2",
|
|
30
31
|
"axon": "^2.0.3",
|
|
31
32
|
"cross-spawn": "^7.0.3",
|
|
33
|
+
"dayjs": "^1.11.7",
|
|
32
34
|
"debug": "^4.3.4",
|
|
35
|
+
"fast-glob": "^3.2.12",
|
|
33
36
|
"find-up": "^5.0.0",
|
|
34
37
|
"flush-write-stream": "^2.0.0",
|
|
35
38
|
"folder-walker": "^3.2.0",
|
|
@@ -50,8 +53,10 @@
|
|
|
50
53
|
"semver": "^7.3.8",
|
|
51
54
|
"semver-sort": "^1.0.0",
|
|
52
55
|
"shelljs": "^0.8.5",
|
|
56
|
+
"slugify": "^1.6.5",
|
|
53
57
|
"stream-to-promise": "^3.0.0",
|
|
54
58
|
"tail": "^2.2.4",
|
|
59
|
+
"tar": "^6.1.11",
|
|
55
60
|
"through2-filter": "^3.0.0",
|
|
56
61
|
"through2-map": "^3.0.0",
|
|
57
62
|
"to-semver": "^3.0.0",
|
|
@@ -62,7 +67,8 @@
|
|
|
62
67
|
"detect-port": "^1.5.1",
|
|
63
68
|
"express": "^4.18.2",
|
|
64
69
|
"fs-extra": "^10.1.0",
|
|
65
|
-
"jest": "^27.5.1"
|
|
70
|
+
"jest": "^27.5.1",
|
|
71
|
+
"unzipper": "^0.10.11"
|
|
66
72
|
},
|
|
67
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "ea6ab48149eb9e1157ef37ab1505fa36a9ce598f"
|
|
68
74
|
}
|