@pisell/core 1.0.41 → 1.0.43
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/es/app/app.d.ts +99 -0
- package/es/applicationManager/application.d.ts +197 -0
- package/es/applicationManager/index.d.ts +19 -0
- package/es/history/index.d.ts +23 -0
- package/es/index.d.ts +7 -0
- package/es/indexDB/index.js +48 -68
- package/es/logger/index.d.ts +1 -1
- package/es/logger/index.js +199 -165
- package/es/menuManager/index.d.ts +28 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/type.d.ts +52 -0
- package/es/request/utils.d.ts +46 -0
- package/es/tasks/index.d.ts +127 -0
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/type.d.ts +100 -0
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/lib/app/app.d.ts +99 -0
- package/lib/applicationManager/application.d.ts +197 -0
- package/lib/applicationManager/index.d.ts +19 -0
- package/lib/history/index.d.ts +23 -0
- package/lib/index.d.ts +7 -0
- package/lib/indexDB/index.js +2 -48
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +21 -6
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/type.d.ts +52 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/tasks/index.d.ts +127 -0
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/type.d.ts +100 -0
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- package/package.json +1 -1
package/es/logger/index.js
CHANGED
|
@@ -65,31 +65,55 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
65
65
|
}
|
|
66
66
|
_createClass(LoggerManager, [{
|
|
67
67
|
key: "init",
|
|
68
|
-
value: function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
value: function () {
|
|
69
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
70
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
71
|
+
while (1) switch (_context.prev = _context.next) {
|
|
72
|
+
case 0:
|
|
73
|
+
this.setStatus("running");
|
|
74
|
+
this.initTimer();
|
|
75
|
+
// 定期清理旧日志
|
|
76
|
+
_context.next = 4;
|
|
77
|
+
return this.cleanupOldLogs();
|
|
78
|
+
case 4:
|
|
79
|
+
_context.prev = 4;
|
|
80
|
+
_context.next = 7;
|
|
81
|
+
return this.uploadIndexDBLog();
|
|
82
|
+
case 7:
|
|
83
|
+
_context.next = 11;
|
|
84
|
+
break;
|
|
85
|
+
case 9:
|
|
86
|
+
_context.prev = 9;
|
|
87
|
+
_context.t0 = _context["catch"](4);
|
|
88
|
+
case 11:
|
|
89
|
+
case "end":
|
|
90
|
+
return _context.stop();
|
|
91
|
+
}
|
|
92
|
+
}, _callee, this, [[4, 9]]);
|
|
93
|
+
}));
|
|
94
|
+
function init() {
|
|
95
|
+
return _init.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
return init;
|
|
98
|
+
}()
|
|
75
99
|
/**
|
|
76
100
|
* 初始化 IndexDB
|
|
77
101
|
*/
|
|
78
102
|
}, {
|
|
79
103
|
key: "initDB",
|
|
80
104
|
value: (function () {
|
|
81
|
-
var _initDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
82
|
-
return _regeneratorRuntime().wrap(function
|
|
83
|
-
while (1) switch (
|
|
105
|
+
var _initDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
106
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
107
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
84
108
|
case 0:
|
|
85
109
|
if (this.app.dbManager) {
|
|
86
110
|
this.db = this.app.dbManager;
|
|
87
111
|
}
|
|
88
112
|
case 1:
|
|
89
113
|
case "end":
|
|
90
|
-
return
|
|
114
|
+
return _context2.stop();
|
|
91
115
|
}
|
|
92
|
-
},
|
|
116
|
+
}, _callee2, this);
|
|
93
117
|
}));
|
|
94
118
|
function initDB() {
|
|
95
119
|
return _initDB.apply(this, arguments);
|
|
@@ -229,11 +253,11 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
229
253
|
}, {
|
|
230
254
|
key: "createAWSFileName",
|
|
231
255
|
value: (function () {
|
|
232
|
-
var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
256
|
+
var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(urgent) {
|
|
233
257
|
var _this$app;
|
|
234
258
|
var _date, _hour, _this$app2, fileName;
|
|
235
|
-
return _regeneratorRuntime().wrap(function
|
|
236
|
-
while (1) switch (
|
|
259
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
260
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
237
261
|
case 0:
|
|
238
262
|
_date = dayjs().format("YYYY-MM-DD");
|
|
239
263
|
_hour = dayjs().format("HH:mm"); // 紧急上传时,在小时后面加上当前时间戳 避免文件名重复覆盖
|
|
@@ -241,22 +265,22 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
241
265
|
_hour = "".concat(dayjs().format("HH:mm"), " [ urgent ] ").concat(dayjs().valueOf());
|
|
242
266
|
}
|
|
243
267
|
if (!((_this$app = this.app) !== null && _this$app !== void 0 && (_this$app = _this$app.getPlugin("aws")) !== null && _this$app !== void 0 && _this$app.createFileName)) {
|
|
244
|
-
|
|
268
|
+
_context3.next = 5;
|
|
245
269
|
break;
|
|
246
270
|
}
|
|
247
|
-
return
|
|
271
|
+
return _context3.abrupt("return", (_this$app2 = this.app) === null || _this$app2 === void 0 || (_this$app2 = _this$app2.getPlugin("aws")) === null || _this$app2 === void 0 ? void 0 : _this$app2.createFileName({
|
|
248
272
|
date: _date,
|
|
249
273
|
hour: _hour,
|
|
250
274
|
isManual: false
|
|
251
275
|
}));
|
|
252
276
|
case 5:
|
|
253
277
|
fileName = "logs/".concat("pisell", "/", _date, "/").concat(_hour);
|
|
254
|
-
return
|
|
278
|
+
return _context3.abrupt("return", "".concat(fileName, ".json"));
|
|
255
279
|
case 7:
|
|
256
280
|
case "end":
|
|
257
|
-
return
|
|
281
|
+
return _context3.stop();
|
|
258
282
|
}
|
|
259
|
-
},
|
|
283
|
+
}, _callee3, this);
|
|
260
284
|
}));
|
|
261
285
|
function createAWSFileName(_x) {
|
|
262
286
|
return _createAWSFileName.apply(this, arguments);
|
|
@@ -290,24 +314,22 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
290
314
|
}, {
|
|
291
315
|
key: "storeLog",
|
|
292
316
|
value: (function () {
|
|
293
|
-
var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
317
|
+
var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(urgent) {
|
|
294
318
|
var _this$logBuffer, fileName, buffer, bufferIds, logs;
|
|
295
|
-
return _regeneratorRuntime().wrap(function
|
|
296
|
-
while (1) switch (
|
|
319
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
320
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
297
321
|
case 0:
|
|
298
|
-
// 每次上传日志时,检查下IndexDB是否有日志,如果有则上传到AWS
|
|
299
|
-
this.uploadIndexDBLog();
|
|
300
322
|
if (!(this.logBuffer.length === 0 || !this.db)) {
|
|
301
|
-
|
|
323
|
+
_context4.next = 2;
|
|
302
324
|
break;
|
|
303
325
|
}
|
|
304
|
-
return
|
|
305
|
-
case
|
|
306
|
-
|
|
307
|
-
|
|
326
|
+
return _context4.abrupt("return");
|
|
327
|
+
case 2:
|
|
328
|
+
_context4.prev = 2;
|
|
329
|
+
_context4.next = 5;
|
|
308
330
|
return this.createAWSFileName(urgent);
|
|
309
|
-
case
|
|
310
|
-
fileName =
|
|
331
|
+
case 5:
|
|
332
|
+
fileName = _context4.sent;
|
|
311
333
|
console.log("-------- 存储日志到AWS 开始", fileName);
|
|
312
334
|
|
|
313
335
|
// 将buffer中的metadata转换为对象
|
|
@@ -319,49 +341,57 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
319
341
|
return item.logId;
|
|
320
342
|
});
|
|
321
343
|
logs = JSON.stringify(buffer, null, 2);
|
|
322
|
-
|
|
344
|
+
_context4.next = 12;
|
|
323
345
|
return this.app.aws.upload({
|
|
324
346
|
Bucket: "",
|
|
325
347
|
Key: fileName,
|
|
326
348
|
Body: logs
|
|
327
349
|
});
|
|
328
|
-
case
|
|
350
|
+
case 12:
|
|
329
351
|
console.log("-------- 存储日志到AWS 成功");
|
|
330
352
|
// 上传成功后需要清空缓冲区,避免重复上传
|
|
331
353
|
this.logBuffer = this.logBuffer.filter(function (item) {
|
|
332
354
|
return !bufferIds.includes(item.logId);
|
|
333
355
|
});
|
|
334
|
-
|
|
356
|
+
_context4.next = 28;
|
|
335
357
|
break;
|
|
336
|
-
case
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
console.error("存储日志上传AWS失败:",
|
|
358
|
+
case 16:
|
|
359
|
+
_context4.prev = 16;
|
|
360
|
+
_context4.t0 = _context4["catch"](2);
|
|
361
|
+
console.error("存储日志上传AWS失败:", _context4.t0);
|
|
340
362
|
|
|
341
363
|
// 将日志存储到IndexDB
|
|
342
|
-
|
|
343
|
-
|
|
364
|
+
_context4.prev = 19;
|
|
365
|
+
_context4.next = 22;
|
|
344
366
|
return this.storeLogToIndexDB();
|
|
345
|
-
case
|
|
346
|
-
|
|
367
|
+
case 22:
|
|
368
|
+
_context4.next = 28;
|
|
347
369
|
break;
|
|
348
|
-
case
|
|
349
|
-
|
|
350
|
-
|
|
370
|
+
case 24:
|
|
371
|
+
_context4.prev = 24;
|
|
372
|
+
_context4.t1 = _context4["catch"](19);
|
|
351
373
|
this.sendFeishuNotification({
|
|
352
374
|
type: "error",
|
|
353
375
|
title: "存储日志到AWS失败",
|
|
354
376
|
metadata: {
|
|
355
|
-
error:
|
|
356
|
-
|
|
377
|
+
error: {
|
|
378
|
+
name: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.name,
|
|
379
|
+
message: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.message,
|
|
380
|
+
stack: _context4.t0 === null || _context4.t0 === void 0 ? void 0 : _context4.t0.stack
|
|
381
|
+
},
|
|
382
|
+
indexDBError: {
|
|
383
|
+
name: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.name,
|
|
384
|
+
message: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.message,
|
|
385
|
+
stack: _context4.t1 === null || _context4.t1 === void 0 ? void 0 : _context4.t1.stack
|
|
386
|
+
}
|
|
357
387
|
}
|
|
358
388
|
});
|
|
359
|
-
console.error("存储日志到IndexDB也失败:",
|
|
360
|
-
case
|
|
389
|
+
console.error("存储日志到IndexDB也失败:", _context4.t1);
|
|
390
|
+
case 28:
|
|
361
391
|
case "end":
|
|
362
|
-
return
|
|
392
|
+
return _context4.stop();
|
|
363
393
|
}
|
|
364
|
-
},
|
|
394
|
+
}, _callee4, this, [[2, 16], [19, 24]]);
|
|
365
395
|
}));
|
|
366
396
|
function storeLog(_x2) {
|
|
367
397
|
return _storeLog.apply(this, arguments);
|
|
@@ -371,34 +401,34 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
371
401
|
}, {
|
|
372
402
|
key: "uploadIndexDBLog",
|
|
373
403
|
value: function () {
|
|
374
|
-
var _uploadIndexDBLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
404
|
+
var _uploadIndexDBLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
375
405
|
var _this$db, _this$db2, logFile, awsFileName, logs;
|
|
376
|
-
return _regeneratorRuntime().wrap(function
|
|
377
|
-
while (1) switch (
|
|
406
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
407
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
378
408
|
case 0:
|
|
379
|
-
|
|
409
|
+
_context5.prev = 0;
|
|
380
410
|
if (this.db) {
|
|
381
|
-
|
|
411
|
+
_context5.next = 3;
|
|
382
412
|
break;
|
|
383
413
|
}
|
|
384
|
-
return
|
|
414
|
+
return _context5.abrupt("return");
|
|
385
415
|
case 3:
|
|
386
|
-
|
|
416
|
+
_context5.next = 5;
|
|
387
417
|
return (_this$db = this.db) === null || _this$db === void 0 ? void 0 : _this$db.getAll("logs");
|
|
388
418
|
case 5:
|
|
389
|
-
logFile =
|
|
419
|
+
logFile = _context5.sent;
|
|
390
420
|
if (!(!logFile || (logFile === null || logFile === void 0 ? void 0 : logFile.length) === 0)) {
|
|
391
|
-
|
|
421
|
+
_context5.next = 8;
|
|
392
422
|
break;
|
|
393
423
|
}
|
|
394
|
-
return
|
|
424
|
+
return _context5.abrupt("return");
|
|
395
425
|
case 8:
|
|
396
|
-
|
|
426
|
+
_context5.next = 10;
|
|
397
427
|
return this.createAWSFileName(true);
|
|
398
428
|
case 10:
|
|
399
|
-
awsFileName =
|
|
429
|
+
awsFileName = _context5.sent;
|
|
400
430
|
logs = JSON.stringify(logFile, null, 2);
|
|
401
|
-
|
|
431
|
+
_context5.next = 14;
|
|
402
432
|
return this.app.aws.upload({
|
|
403
433
|
Bucket: "",
|
|
404
434
|
Key: awsFileName,
|
|
@@ -406,30 +436,34 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
406
436
|
});
|
|
407
437
|
case 14:
|
|
408
438
|
console.log("-------- 存储日志到AWS 成功");
|
|
409
|
-
|
|
439
|
+
_context5.next = 17;
|
|
410
440
|
return (_this$db2 = this.db) === null || _this$db2 === void 0 ? void 0 : _this$db2.clear("logs");
|
|
411
441
|
case 17:
|
|
412
442
|
console.log("-------- 清空IndexDB日志成功");
|
|
413
|
-
|
|
443
|
+
_context5.next = 25;
|
|
414
444
|
break;
|
|
415
445
|
case 20:
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
console.log("-------- 存储日志到IndexDB 失败",
|
|
446
|
+
_context5.prev = 20;
|
|
447
|
+
_context5.t0 = _context5["catch"](0);
|
|
448
|
+
console.log("-------- 存储日志到IndexDB 失败", _context5.t0);
|
|
419
449
|
this.sendFeishuNotification({
|
|
420
450
|
type: "error",
|
|
421
451
|
title: "存储IndexDB日志到AWS失败",
|
|
422
452
|
metadata: {
|
|
423
|
-
error:
|
|
453
|
+
error: {
|
|
454
|
+
name: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.name,
|
|
455
|
+
message: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message,
|
|
456
|
+
stack: _context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.stack
|
|
457
|
+
}
|
|
424
458
|
}
|
|
425
459
|
});
|
|
426
460
|
// 重新抛出错误,让外层 catch 能够捕获
|
|
427
|
-
throw
|
|
461
|
+
throw _context5.t0;
|
|
428
462
|
case 25:
|
|
429
463
|
case "end":
|
|
430
|
-
return
|
|
464
|
+
return _context5.stop();
|
|
431
465
|
}
|
|
432
|
-
},
|
|
466
|
+
}, _callee5, this, [[0, 20]]);
|
|
433
467
|
}));
|
|
434
468
|
function uploadIndexDBLog() {
|
|
435
469
|
return _uploadIndexDBLog.apply(this, arguments);
|
|
@@ -439,32 +473,32 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
439
473
|
}, {
|
|
440
474
|
key: "storeLogToIndexDB",
|
|
441
475
|
value: function () {
|
|
442
|
-
var _storeLogToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
476
|
+
var _storeLogToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
443
477
|
var _this$db3, _this$db5, fileName, buffer, logFile, _this$db4, bufferIds;
|
|
444
|
-
return _regeneratorRuntime().wrap(function
|
|
445
|
-
while (1) switch (
|
|
478
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
479
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
446
480
|
case 0:
|
|
447
|
-
|
|
481
|
+
_context6.prev = 0;
|
|
448
482
|
fileName = this.createFileName();
|
|
449
483
|
console.log("storeLog", fileName);
|
|
450
484
|
buffer = this.logBuffer || []; // 获取现有日志文件
|
|
451
|
-
|
|
485
|
+
_context6.next = 6;
|
|
452
486
|
return (_this$db3 = this.db) === null || _this$db3 === void 0 ? void 0 : _this$db3.get("logs", fileName);
|
|
453
487
|
case 6:
|
|
454
|
-
logFile =
|
|
488
|
+
logFile = _context6.sent;
|
|
455
489
|
if (logFile) {
|
|
456
|
-
|
|
490
|
+
_context6.next = 11;
|
|
457
491
|
break;
|
|
458
492
|
}
|
|
459
493
|
logFile = this.createFile(fileName);
|
|
460
|
-
|
|
494
|
+
_context6.next = 11;
|
|
461
495
|
return (_this$db4 = this.db) === null || _this$db4 === void 0 ? void 0 : _this$db4.add("logs", logFile);
|
|
462
496
|
case 11:
|
|
463
497
|
// 添加日志到文件内容
|
|
464
498
|
logFile.fileContent.logs = [].concat(_toConsumableArray(logFile.fileContent.logs), _toConsumableArray(buffer));
|
|
465
499
|
|
|
466
500
|
// 更新日志文件
|
|
467
|
-
|
|
501
|
+
_context6.next = 14;
|
|
468
502
|
return (_this$db5 = this.db) === null || _this$db5 === void 0 ? void 0 : _this$db5.update("logs", logFile);
|
|
469
503
|
case 14:
|
|
470
504
|
console.log("-------- 存储日志到IndexDB", {
|
|
@@ -477,19 +511,19 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
477
511
|
this.logBuffer = this.logBuffer.filter(function (item) {
|
|
478
512
|
return !bufferIds.includes(item.logId);
|
|
479
513
|
});
|
|
480
|
-
|
|
514
|
+
_context6.next = 23;
|
|
481
515
|
break;
|
|
482
516
|
case 19:
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
console.log("-------- 存储日志到IndexDB 失败",
|
|
517
|
+
_context6.prev = 19;
|
|
518
|
+
_context6.t0 = _context6["catch"](0);
|
|
519
|
+
console.log("-------- 存储日志到IndexDB 失败", _context6.t0);
|
|
486
520
|
// 重新抛出错误,让外层 catch 能够捕获
|
|
487
|
-
throw
|
|
521
|
+
throw _context6.t0;
|
|
488
522
|
case 23:
|
|
489
523
|
case "end":
|
|
490
|
-
return
|
|
524
|
+
return _context6.stop();
|
|
491
525
|
}
|
|
492
|
-
},
|
|
526
|
+
}, _callee6, this, [[0, 19]]);
|
|
493
527
|
}));
|
|
494
528
|
function storeLogToIndexDB() {
|
|
495
529
|
return _storeLogToIndexDB.apply(this, arguments);
|
|
@@ -502,22 +536,22 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
502
536
|
}, {
|
|
503
537
|
key: "cleanupOldLogs",
|
|
504
538
|
value: (function () {
|
|
505
|
-
var _cleanupOldLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
539
|
+
var _cleanupOldLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
506
540
|
var logFiles, cutoffDate, filesToDelete, _iterator, _step, file;
|
|
507
|
-
return _regeneratorRuntime().wrap(function
|
|
508
|
-
while (1) switch (
|
|
541
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
542
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
509
543
|
case 0:
|
|
510
544
|
if (this.db) {
|
|
511
|
-
|
|
545
|
+
_context7.next = 2;
|
|
512
546
|
break;
|
|
513
547
|
}
|
|
514
|
-
return
|
|
548
|
+
return _context7.abrupt("return");
|
|
515
549
|
case 2:
|
|
516
|
-
|
|
517
|
-
|
|
550
|
+
_context7.prev = 2;
|
|
551
|
+
_context7.next = 5;
|
|
518
552
|
return this.getLogFiles();
|
|
519
553
|
case 5:
|
|
520
|
-
logFiles =
|
|
554
|
+
logFiles = _context7.sent;
|
|
521
555
|
// 计算保留日志的截止日期
|
|
522
556
|
cutoffDate = dayjs().subtract(this.retentionDays, "day").format("YYYY-MM-DD"); // 筛选出需要删除的日志文件
|
|
523
557
|
filesToDelete = logFiles.filter(function (file) {
|
|
@@ -527,47 +561,47 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
527
561
|
|
|
528
562
|
// 删除旧日志文件
|
|
529
563
|
_iterator = _createForOfIteratorHelper(filesToDelete);
|
|
530
|
-
|
|
564
|
+
_context7.prev = 10;
|
|
531
565
|
_iterator.s();
|
|
532
566
|
case 12:
|
|
533
567
|
if ((_step = _iterator.n()).done) {
|
|
534
|
-
|
|
568
|
+
_context7.next = 19;
|
|
535
569
|
break;
|
|
536
570
|
}
|
|
537
571
|
file = _step.value;
|
|
538
|
-
|
|
572
|
+
_context7.next = 16;
|
|
539
573
|
return this.db.delete("logs", file.fileName);
|
|
540
574
|
case 16:
|
|
541
575
|
console.log("-------- \u5220\u9664\u65E7\u65E5\u5FD7\u6587\u4EF6: ".concat(file.fileName, ", \u65E5\u671F: ").concat(file.date));
|
|
542
576
|
case 17:
|
|
543
|
-
|
|
577
|
+
_context7.next = 12;
|
|
544
578
|
break;
|
|
545
579
|
case 19:
|
|
546
|
-
|
|
580
|
+
_context7.next = 24;
|
|
547
581
|
break;
|
|
548
582
|
case 21:
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
_iterator.e(
|
|
583
|
+
_context7.prev = 21;
|
|
584
|
+
_context7.t0 = _context7["catch"](10);
|
|
585
|
+
_iterator.e(_context7.t0);
|
|
552
586
|
case 24:
|
|
553
|
-
|
|
587
|
+
_context7.prev = 24;
|
|
554
588
|
_iterator.f();
|
|
555
|
-
return
|
|
589
|
+
return _context7.finish(24);
|
|
556
590
|
case 27:
|
|
557
591
|
if (filesToDelete.length > 0) {
|
|
558
592
|
console.log("-------- \u5171\u6E05\u7406 ".concat(filesToDelete.length, " \u4E2A\u65E7\u65E5\u5FD7\u6587\u4EF6"));
|
|
559
593
|
}
|
|
560
|
-
|
|
594
|
+
_context7.next = 33;
|
|
561
595
|
break;
|
|
562
596
|
case 30:
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
console.error("清理旧日志失败:",
|
|
597
|
+
_context7.prev = 30;
|
|
598
|
+
_context7.t1 = _context7["catch"](2);
|
|
599
|
+
console.error("清理旧日志失败:", _context7.t1);
|
|
566
600
|
case 33:
|
|
567
601
|
case "end":
|
|
568
|
-
return
|
|
602
|
+
return _context7.stop();
|
|
569
603
|
}
|
|
570
|
-
},
|
|
604
|
+
}, _callee7, this, [[2, 30], [10, 21, 24, 27]]);
|
|
571
605
|
}));
|
|
572
606
|
function cleanupOldLogs() {
|
|
573
607
|
return _cleanupOldLogs.apply(this, arguments);
|
|
@@ -582,31 +616,31 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
582
616
|
}, {
|
|
583
617
|
key: "getLogFiles",
|
|
584
618
|
value: (function () {
|
|
585
|
-
var _getLogFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
586
|
-
return _regeneratorRuntime().wrap(function
|
|
587
|
-
while (1) switch (
|
|
619
|
+
var _getLogFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
620
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
621
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
588
622
|
case 0:
|
|
589
623
|
if (this.db) {
|
|
590
|
-
|
|
624
|
+
_context8.next = 2;
|
|
591
625
|
break;
|
|
592
626
|
}
|
|
593
|
-
return
|
|
627
|
+
return _context8.abrupt("return", []);
|
|
594
628
|
case 2:
|
|
595
|
-
|
|
596
|
-
|
|
629
|
+
_context8.prev = 2;
|
|
630
|
+
_context8.next = 5;
|
|
597
631
|
return this.db.getAll("logs");
|
|
598
632
|
case 5:
|
|
599
|
-
return
|
|
633
|
+
return _context8.abrupt("return", _context8.sent);
|
|
600
634
|
case 8:
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
console.error("获取日志文件列表失败:",
|
|
604
|
-
return
|
|
635
|
+
_context8.prev = 8;
|
|
636
|
+
_context8.t0 = _context8["catch"](2);
|
|
637
|
+
console.error("获取日志文件列表失败:", _context8.t0);
|
|
638
|
+
return _context8.abrupt("return", []);
|
|
605
639
|
case 12:
|
|
606
640
|
case "end":
|
|
607
|
-
return
|
|
641
|
+
return _context8.stop();
|
|
608
642
|
}
|
|
609
|
-
},
|
|
643
|
+
}, _callee8, this, [[2, 8]]);
|
|
610
644
|
}));
|
|
611
645
|
function getLogFiles() {
|
|
612
646
|
return _getLogFiles.apply(this, arguments);
|
|
@@ -622,31 +656,31 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
622
656
|
}, {
|
|
623
657
|
key: "getLogFile",
|
|
624
658
|
value: (function () {
|
|
625
|
-
var _getLogFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
626
|
-
return _regeneratorRuntime().wrap(function
|
|
627
|
-
while (1) switch (
|
|
659
|
+
var _getLogFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(fileName) {
|
|
660
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
661
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
628
662
|
case 0:
|
|
629
663
|
if (this.db) {
|
|
630
|
-
|
|
664
|
+
_context9.next = 2;
|
|
631
665
|
break;
|
|
632
666
|
}
|
|
633
|
-
return
|
|
667
|
+
return _context9.abrupt("return", null);
|
|
634
668
|
case 2:
|
|
635
|
-
|
|
636
|
-
|
|
669
|
+
_context9.prev = 2;
|
|
670
|
+
_context9.next = 5;
|
|
637
671
|
return this.db.get("logs", fileName);
|
|
638
672
|
case 5:
|
|
639
|
-
return
|
|
673
|
+
return _context9.abrupt("return", _context9.sent);
|
|
640
674
|
case 8:
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
console.error("获取日志文件内容失败:",
|
|
644
|
-
return
|
|
675
|
+
_context9.prev = 8;
|
|
676
|
+
_context9.t0 = _context9["catch"](2);
|
|
677
|
+
console.error("获取日志文件内容失败:", _context9.t0);
|
|
678
|
+
return _context9.abrupt("return", null);
|
|
645
679
|
case 12:
|
|
646
680
|
case "end":
|
|
647
|
-
return
|
|
681
|
+
return _context9.stop();
|
|
648
682
|
}
|
|
649
|
-
},
|
|
683
|
+
}, _callee9, this, [[2, 8]]);
|
|
650
684
|
}));
|
|
651
685
|
function getLogFile(_x3) {
|
|
652
686
|
return _getLogFile.apply(this, arguments);
|
|
@@ -662,41 +696,41 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
662
696
|
}, {
|
|
663
697
|
key: "clearLogs",
|
|
664
698
|
value: (function () {
|
|
665
|
-
var _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
666
|
-
return _regeneratorRuntime().wrap(function
|
|
667
|
-
while (1) switch (
|
|
699
|
+
var _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(fileName) {
|
|
700
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
701
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
668
702
|
case 0:
|
|
669
703
|
if (this.db) {
|
|
670
|
-
|
|
704
|
+
_context10.next = 2;
|
|
671
705
|
break;
|
|
672
706
|
}
|
|
673
|
-
return
|
|
707
|
+
return _context10.abrupt("return", false);
|
|
674
708
|
case 2:
|
|
675
|
-
|
|
709
|
+
_context10.prev = 2;
|
|
676
710
|
if (!fileName) {
|
|
677
|
-
|
|
711
|
+
_context10.next = 8;
|
|
678
712
|
break;
|
|
679
713
|
}
|
|
680
|
-
|
|
714
|
+
_context10.next = 6;
|
|
681
715
|
return this.db.delete("logs", fileName);
|
|
682
716
|
case 6:
|
|
683
|
-
|
|
717
|
+
_context10.next = 10;
|
|
684
718
|
break;
|
|
685
719
|
case 8:
|
|
686
|
-
|
|
720
|
+
_context10.next = 10;
|
|
687
721
|
return this.db.clear("logs");
|
|
688
722
|
case 10:
|
|
689
|
-
return
|
|
723
|
+
return _context10.abrupt("return", true);
|
|
690
724
|
case 13:
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
console.error("清空日志失败:",
|
|
694
|
-
return
|
|
725
|
+
_context10.prev = 13;
|
|
726
|
+
_context10.t0 = _context10["catch"](2);
|
|
727
|
+
console.error("清空日志失败:", _context10.t0);
|
|
728
|
+
return _context10.abrupt("return", false);
|
|
695
729
|
case 17:
|
|
696
730
|
case "end":
|
|
697
|
-
return
|
|
731
|
+
return _context10.stop();
|
|
698
732
|
}
|
|
699
|
-
},
|
|
733
|
+
}, _callee10, this, [[2, 13]]);
|
|
700
734
|
}));
|
|
701
735
|
function clearLogs(_x4) {
|
|
702
736
|
return _clearLogs.apply(this, arguments);
|
|
@@ -725,17 +759,17 @@ var LoggerManager = /*#__PURE__*/function () {
|
|
|
725
759
|
}, {
|
|
726
760
|
key: "manualCleanup",
|
|
727
761
|
value: (function () {
|
|
728
|
-
var _manualCleanup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
729
|
-
return _regeneratorRuntime().wrap(function
|
|
730
|
-
while (1) switch (
|
|
762
|
+
var _manualCleanup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
763
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
764
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
731
765
|
case 0:
|
|
732
|
-
|
|
766
|
+
_context11.next = 2;
|
|
733
767
|
return this.cleanupOldLogs();
|
|
734
768
|
case 2:
|
|
735
769
|
case "end":
|
|
736
|
-
return
|
|
770
|
+
return _context11.stop();
|
|
737
771
|
}
|
|
738
|
-
},
|
|
772
|
+
}, _callee11, this);
|
|
739
773
|
}));
|
|
740
774
|
function manualCleanup() {
|
|
741
775
|
return _manualCleanup.apply(this, arguments);
|