datafolder 1.0.52 → 1.0.53
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/ChangeLog.md +2 -0
- package/package.json +1 -1
- package/scripts/convertBinFiles.js +7 -7
- package/src/QyCache.d.ts +5 -2
- package/src/QyCache.js +90 -66
- package/src/QyDefaultOptions.js +4 -4
- package/src/QyFileLogger.d.ts +5 -4
- package/src/QyFileLogger.js +20 -17
- package/src/QyKVData.d.ts +1 -2
- package/src/QyKVData.js +77 -99
- package/src/QyKVDataUtils.d.ts +5 -0
- package/src/QyKVDataUtils.js +31 -0
- package/src/QyLogFileSaver.d.ts +1 -1
- package/src/QyLogFileSaver.js +7 -7
- package/src/QyLogFileSaver_Worker.d.ts +11 -5
- package/src/QyLogFileSaver_Worker.js +63 -12
- package/src/QyLogger.d.ts +12 -14
- package/src/QyLogger.js +129 -92
- package/src/QyMessager.d.ts +3 -1
- package/src/QyMessager.js +15 -12
- package/src/QyUtils.d.ts +1 -1
package/src/QyKVData.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "node:path";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
open as
|
|
6
|
+
open as S
|
|
7
7
|
} from "node:fs/promises";
|
|
8
8
|
|
|
9
9
|
import {
|
|
@@ -15,16 +15,16 @@ import {
|
|
|
15
15
|
} from "./QyKVDataSaver.js";
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
|
-
QySnapshotCompactor as
|
|
18
|
+
QySnapshotCompactor as p
|
|
19
19
|
} from "./QySnapshotCompactor.js";
|
|
20
20
|
|
|
21
21
|
import {
|
|
22
|
-
QyKVDataCleaner as
|
|
22
|
+
QyKVDataCleaner as i
|
|
23
23
|
} from "./QyKVDataCleaner.js";
|
|
24
24
|
|
|
25
25
|
import {
|
|
26
|
-
readBufferAsync as
|
|
27
|
-
sleep as
|
|
26
|
+
readBufferAsync as v,
|
|
27
|
+
sleep as c
|
|
28
28
|
} from "./QyUtils.js";
|
|
29
29
|
|
|
30
30
|
import {
|
|
@@ -36,11 +36,11 @@ import {
|
|
|
36
36
|
} from "./QyExpireMonitor.js";
|
|
37
37
|
|
|
38
38
|
import {
|
|
39
|
-
getPMFilePath as
|
|
39
|
+
getPMFilePath as C
|
|
40
40
|
} from "./QySnapshots.js";
|
|
41
41
|
|
|
42
42
|
import {
|
|
43
|
-
QyKVDataLoader as
|
|
43
|
+
QyKVDataLoader as m
|
|
44
44
|
} from "./QyKVDataLoader.js";
|
|
45
45
|
|
|
46
46
|
class t {
|
|
@@ -55,10 +55,8 @@ class t {
|
|
|
55
55
|
loadedMaxAclNum = 0;
|
|
56
56
|
emptySnapshotNumVerList = [];
|
|
57
57
|
isStopping = !1;
|
|
58
|
-
unloadingMemory = !1;
|
|
59
58
|
keyValueMap;
|
|
60
59
|
compactInterval;
|
|
61
|
-
unloadInterval;
|
|
62
60
|
qySnapshots;
|
|
63
61
|
qyKVDataSaver;
|
|
64
62
|
qySnapshotCompactor;
|
|
@@ -71,17 +69,21 @@ class t {
|
|
|
71
69
|
};
|
|
72
70
|
var e = s(t, "snapshot");
|
|
73
71
|
this.qyCache = o, this.options = a, this.kvFolder = t, this.snapshotFolder = e,
|
|
74
|
-
this.qyKVDataSaver = new r(this, t, a), this.qySnapshotCompactor = new
|
|
75
|
-
this.qyKVDataCleaner = new
|
|
72
|
+
this.qyKVDataSaver = new r(this, t, a), this.qySnapshotCompactor = new p(this, t, a),
|
|
73
|
+
this.qyKVDataCleaner = new i(this, t, a), this.qyExpireMonitor = new h(o, a);
|
|
74
|
+
}
|
|
75
|
+
get snapshotMaxChangeId() {
|
|
76
|
+
return this.qySnapshots?.snapshotMaxChangeId ?? 0;
|
|
76
77
|
}
|
|
77
78
|
async load() {
|
|
78
79
|
var {
|
|
79
80
|
kvFolder: t,
|
|
80
81
|
options: a
|
|
81
|
-
} = this, [ t, a, o, e ] = await new
|
|
82
|
+
} = this, [ t, a, o, e ] = await new m(t, a).load();
|
|
82
83
|
this.maxChangeId = t, this.qySnapshots = o, this.keyValueMap = e, this.loadedMaxAclNum = a;
|
|
83
84
|
}
|
|
84
85
|
start() {
|
|
86
|
+
this.isStopping = !1;
|
|
85
87
|
var {
|
|
86
88
|
maxChangeId: t,
|
|
87
89
|
loadedMaxAclNum: a,
|
|
@@ -90,71 +92,55 @@ class t {
|
|
|
90
92
|
options: s,
|
|
91
93
|
qyKVDataSaver: n,
|
|
92
94
|
qySnapshotCompactor: r,
|
|
93
|
-
qyKVDataCleaner:
|
|
94
|
-
qyExpireMonitor:
|
|
95
|
+
qyKVDataCleaner: p,
|
|
96
|
+
qyExpireMonitor: i
|
|
95
97
|
} = this, {
|
|
96
98
|
maxSnapshotNum: o,
|
|
97
99
|
snapshotMaxChangeId: h
|
|
98
100
|
} = o;
|
|
99
|
-
return n.call_start(t, o, a, e), r.call_start(),
|
|
100
|
-
this.snapshotSavedChangeId = h, this.compactInterval = setInterval(() =>
|
|
101
|
-
|
|
102
|
-
if (!o.unloadingMemory) {
|
|
103
|
-
o.unloadingMemory = !0;
|
|
104
|
-
var {
|
|
105
|
-
qyCache: e,
|
|
106
|
-
options: s
|
|
107
|
-
} = o;
|
|
108
|
-
let t = 0, a = 0;
|
|
109
|
-
if (e) {
|
|
110
|
-
var n, r = s.maxFileCountToUnload, s = e.rootDir;
|
|
111
|
-
a = u(o, s), t = a;
|
|
112
|
-
for (n of s.allLoadedSubdirs()) if ((a += u(o, n)) > r && (t += a,
|
|
113
|
-
a = 0, await l(0), o.isStopping)) break;
|
|
114
|
-
}
|
|
115
|
-
t += a, global.gc && global.gc(), o.unloadingMemory = !1;
|
|
116
|
-
}
|
|
117
|
-
})(this), s.unloadMemInterval), s.bgLoadPosMaps ? (async t => {
|
|
101
|
+
return n.call_start(t, o, a, e), r.call_start(), p.call_start(), i.start(),
|
|
102
|
+
this.snapshotSavedChangeId = h, this.compactInterval = setInterval(() => l(this), s.compactSnapshotsInterval),
|
|
103
|
+
s.bgLoadPosMaps ? (async t => {
|
|
118
104
|
var a, {
|
|
119
105
|
qySnapshots: o,
|
|
120
106
|
options: e
|
|
121
107
|
} = t;
|
|
122
108
|
console.time("bgLoadPosMaps");
|
|
123
109
|
for (a of o.numToSnapshotMap.keys().toArray().sort((t, a) => a - t)) {
|
|
124
|
-
if (await async function n(r,
|
|
125
|
-
if (r.isStopping) return void (
|
|
110
|
+
if (await async function n(r, p, i = void 0, h = void 0, c = void 0, m = void 0) {
|
|
111
|
+
if (r.isStopping) return void (m && m.close());
|
|
126
112
|
let {
|
|
127
113
|
snapshotFolder: t,
|
|
128
114
|
qySnapshots: d
|
|
129
115
|
} = r;
|
|
130
|
-
let
|
|
131
|
-
let u =
|
|
132
|
-
if (void 0 === u) return void (
|
|
116
|
+
let l = d.numToSnapshotMap;
|
|
117
|
+
let u = l.get(p);
|
|
118
|
+
if (void 0 === u) return void (m && m.close());
|
|
133
119
|
let {
|
|
134
120
|
info: y,
|
|
135
121
|
prefixPM: f
|
|
136
122
|
} = u;
|
|
137
|
-
void 0 ===
|
|
138
|
-
if (0 ===
|
|
139
|
-
if (void 0 === h || h !== y.pMVersion) return
|
|
140
|
-
|
|
141
|
-
for (;0 <
|
|
142
|
-
let e =
|
|
123
|
+
void 0 === i && (i = f.keys().toArray().sort().reverse());
|
|
124
|
+
if (0 === i.length) return void (m && m.close());
|
|
125
|
+
if (void 0 === h || h !== y.pMVersion) return m && m.close(),
|
|
126
|
+
c = C(t, u.snapshotNum, y.pMVersion), n(r, p, i, y.pMVersion, c, await S(c));
|
|
127
|
+
for (;0 < i.length; ) {
|
|
128
|
+
let e = i.at(-1), s = f.get(e);
|
|
143
129
|
if (s) {
|
|
144
|
-
let [ t, a ] = s, o = await
|
|
145
|
-
if (r.isStopping || void 0 ===
|
|
146
|
-
if (h !== y.pMVersion) return
|
|
130
|
+
let [ t, a ] = s, o = await v(c, m, t, a);
|
|
131
|
+
if (r.isStopping || void 0 === l.get(p)) return void m.close();
|
|
132
|
+
if (h !== y.pMVersion) return m.close(), n(r, p, i);
|
|
147
133
|
f.has(e) && d.loadPartialPosMapBuffer(u, e, o);
|
|
148
134
|
}
|
|
149
|
-
|
|
135
|
+
i.pop();
|
|
150
136
|
}
|
|
151
|
-
|
|
152
|
-
g.info("bgLoadPosMap:" +
|
|
137
|
+
m.close();
|
|
138
|
+
g.info("bgLoadPosMap:" + p);
|
|
153
139
|
}(t, a), t.isStopping) break;
|
|
154
|
-
if (await
|
|
140
|
+
if (await c(0), t.isStopping) break;
|
|
155
141
|
}
|
|
156
|
-
console.timeEnd("bgLoadPosMaps"), !t.isStopping && e.compactAtStart &&
|
|
157
|
-
})(this) : s.compactAtStart &&
|
|
142
|
+
console.timeEnd("bgLoadPosMaps"), !t.isStopping && e.compactAtStart && l(t);
|
|
143
|
+
})(this) : s.compactAtStart && l(this), this;
|
|
158
144
|
}
|
|
159
145
|
async stop() {
|
|
160
146
|
this.isStopping = !0;
|
|
@@ -163,12 +149,11 @@ class t {
|
|
|
163
149
|
qySnapshotCompactor: a,
|
|
164
150
|
qySnapshots: o,
|
|
165
151
|
compactInterval: e,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
qyExpireMonitor: r
|
|
152
|
+
qyKVDataCleaner: s,
|
|
153
|
+
qyExpireMonitor: n
|
|
169
154
|
} = this;
|
|
170
|
-
clearInterval(e),
|
|
171
|
-
|
|
155
|
+
clearInterval(e), await n.stop(), d(this, await t.call_stop()), o && o.closeAllFDs(),
|
|
156
|
+
await a.call_stop(), await s.call_stop();
|
|
172
157
|
}
|
|
173
158
|
save(t, a, o, e) {
|
|
174
159
|
var s = this.qyKVDataSaver;
|
|
@@ -199,41 +184,41 @@ class t {
|
|
|
199
184
|
_on_snapshotSavedChangeId(t, a) {
|
|
200
185
|
d(this, t, a);
|
|
201
186
|
}
|
|
202
|
-
_on_compactUpdates(
|
|
187
|
+
_on_compactUpdates(m) {
|
|
203
188
|
if (2 === this.compactState) {
|
|
204
|
-
var d = this, [
|
|
205
|
-
if (
|
|
189
|
+
var d = this, [ m, t, l ] = m = m;
|
|
190
|
+
if (m) {
|
|
206
191
|
var a, o = d.qySnapshots.numToSnapshotMap;
|
|
207
|
-
for ([ s, a ] of
|
|
192
|
+
for ([ s, a ] of m) {
|
|
208
193
|
var e, s = o.get(s), {
|
|
209
194
|
prefixPM: n,
|
|
210
195
|
info: r,
|
|
211
|
-
compactOutedCount:
|
|
196
|
+
compactOutedCount: p
|
|
212
197
|
} = s;
|
|
213
198
|
++r.pMVersion, r.verList[0] = r.pMVersion + r.vLVersion;
|
|
214
199
|
for (e of n.keys()) n.set(e, a.get(e));
|
|
215
|
-
r.outdatedCount +=
|
|
200
|
+
r.outdatedCount += p, s.curOutdatedCount -= p, s.compactOutedCount = 0;
|
|
216
201
|
}
|
|
217
202
|
}
|
|
218
203
|
if (t) {
|
|
219
|
-
var
|
|
204
|
+
var i = (m = d).qySnapshots.numToSnapshotMap;
|
|
220
205
|
for ([ g, f ] of t) {
|
|
221
|
-
var h,
|
|
206
|
+
var h, c, {
|
|
222
207
|
posMap: u,
|
|
223
208
|
prefixPM: y
|
|
224
|
-
} = f, f =
|
|
225
|
-
posMap:
|
|
226
|
-
prefixPM:
|
|
209
|
+
} = f, f = i.get(g), {
|
|
210
|
+
posMap: S,
|
|
211
|
+
prefixPM: v,
|
|
227
212
|
info: g
|
|
228
213
|
} = f;
|
|
229
214
|
++g.pMVersion, ++g.vLVersion, g.verList[0] = g.pMVersion + g.vLVersion;
|
|
230
|
-
for (h of
|
|
231
|
-
for (
|
|
215
|
+
for (h of S.keys()) S.set(h, u.get(h));
|
|
216
|
+
for (c of v.keys()) v.set(c, y.get(c));
|
|
232
217
|
x(f);
|
|
233
218
|
}
|
|
234
219
|
}
|
|
235
|
-
if (
|
|
236
|
-
var
|
|
220
|
+
if (l) {
|
|
221
|
+
var C, m = l;
|
|
237
222
|
let e = d.qySnapshots, {
|
|
238
223
|
numToSnapshotMap: s,
|
|
239
224
|
keyToSnapshotMap: n
|
|
@@ -241,24 +226,24 @@ class t {
|
|
|
241
226
|
snapshotNum: t,
|
|
242
227
|
combinedSnapshotNumVerList: a,
|
|
243
228
|
posMap: r
|
|
244
|
-
} =
|
|
245
|
-
posMap:
|
|
229
|
+
} = m, p = s.get(t), {
|
|
230
|
+
posMap: i,
|
|
246
231
|
info: o
|
|
247
|
-
} =
|
|
232
|
+
} = p;
|
|
248
233
|
++o.pMVersion, ++o.vLVersion, o.verList[0] = o.pMVersion + o.vLVersion;
|
|
249
|
-
for (
|
|
250
|
-
x(
|
|
251
|
-
let h = o.totalCount,
|
|
234
|
+
for (C of i.keys()) i.set(C, r.get(C));
|
|
235
|
+
x(p);
|
|
236
|
+
let h = o.totalCount, c = p.curOutdatedCount;
|
|
252
237
|
for (let [ o ] of a) {
|
|
253
|
-
var
|
|
238
|
+
var M, V = s.get(o);
|
|
254
239
|
let {
|
|
255
240
|
posMap: t,
|
|
256
241
|
info: a
|
|
257
242
|
} = V;
|
|
258
|
-
for (
|
|
259
|
-
x(V), h += a.totalCount,
|
|
243
|
+
for (M of t.keys()) i.set(M, r.get(M)), n.set(M, p);
|
|
244
|
+
x(V), h += a.totalCount, c += V.curOutdatedCount, e.delSnapshot(V);
|
|
260
245
|
}
|
|
261
|
-
o.totalCount = h,
|
|
246
|
+
o.totalCount = h, p.curOutdatedCount = c;
|
|
262
247
|
}
|
|
263
248
|
this.snapshotSavedChangeId >= this.compactMaxChangeId ? (q(this), this.compactState = 1) : this.compactState = 3;
|
|
264
249
|
}
|
|
@@ -285,12 +270,12 @@ function d(t, a, o = void 0) {
|
|
|
285
270
|
qyKVDataSaver: n
|
|
286
271
|
} = t;
|
|
287
272
|
if (3 === e && s <= a && (q(t), t.compactState = 1), o) {
|
|
288
|
-
var r, e = o,
|
|
273
|
+
var r, e = o, p = t.qySnapshots, i = p.keyToSnapshotMap;
|
|
289
274
|
for (r of e.posMap.keys()) {
|
|
290
|
-
var h =
|
|
291
|
-
h &&
|
|
275
|
+
var h = i.get(r);
|
|
276
|
+
h && p.removeKeyFromSnapshot(h, r);
|
|
292
277
|
}
|
|
293
|
-
|
|
278
|
+
p.addMaxSnapshot(e), g.info("addPMOnlySnapshot: " + p.snapshotMaxChangeId),
|
|
294
279
|
n.cast_releaseSnapshot(o.snapshotNum);
|
|
295
280
|
}
|
|
296
281
|
}
|
|
@@ -304,7 +289,7 @@ function x(t) {
|
|
|
304
289
|
t.compactOutedCount = 0;
|
|
305
290
|
}
|
|
306
291
|
|
|
307
|
-
function
|
|
292
|
+
function l(t) {
|
|
308
293
|
if (1 === t.compactState) {
|
|
309
294
|
var {
|
|
310
295
|
maxChangeId: a,
|
|
@@ -313,22 +298,15 @@ function m(t) {
|
|
|
313
298
|
} = t, [ o, s, n, r ] = o.calOutdates();
|
|
314
299
|
if (0 < s.length || 0 < n.length || 0 < r.length) {
|
|
315
300
|
t.compactState = 2, t.compactMaxChangeId = a;
|
|
316
|
-
for (var
|
|
301
|
+
for (var p of [ n, r, s ]) for (var i of p) i.compactOutedCount = i.curOutdatedCount;
|
|
317
302
|
e.cast_compactSnapshots(n, r, s);
|
|
318
303
|
}
|
|
319
|
-
0 < o.length && (t.emptySnapshotNumVerList.push(...o), t.snapshotSavedChangeId >= a ?
|
|
304
|
+
0 < o.length && (t.emptySnapshotNumVerList.push(...o), t.snapshotSavedChangeId >= a ? u(t) : 1 === t.compactState && (t.compactState = 3,
|
|
320
305
|
t.compactMaxChangeId = a));
|
|
321
306
|
}
|
|
322
307
|
}
|
|
323
308
|
|
|
324
|
-
function u(t
|
|
325
|
-
var o = t.qySnapshots.snapshotMaxChangeId;
|
|
326
|
-
let e = 0;
|
|
327
|
-
if (a.fileMapLoaded) for (var s of a.fileList) ++e, s.cChangeId <= o && (s.visited ? s.visited = !1 : s.unloadFileContent());
|
|
328
|
-
return e;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function y(t) {
|
|
309
|
+
function u(t) {
|
|
332
310
|
var {
|
|
333
311
|
qyKVDataCleaner: t,
|
|
334
312
|
emptySnapshotNumVerList: a
|
|
@@ -337,7 +315,7 @@ function y(t) {
|
|
|
337
315
|
}
|
|
338
316
|
|
|
339
317
|
function q(t) {
|
|
340
|
-
t.qySnapshotCompactor.cast_saveSnapshotInfos(),
|
|
318
|
+
t.qySnapshotCompactor.cast_saveSnapshotInfos(), u(t);
|
|
341
319
|
}
|
|
342
320
|
|
|
343
321
|
export {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getSnapshotInfoFileName(snapshotNum: any, version: any): string;
|
|
2
|
+
export declare function getVLFilePath(snapshotFolder: any, snapshotNum: any, vLVersion: any): string;
|
|
3
|
+
export declare function getPMFilePath(snapshotFolder: any, snapshotNum: any, pMVersion: any): string;
|
|
4
|
+
export declare function getPrefixPMFilePath(snapshotFolder: any, snapshotNum: any, pMVersion: any): string;
|
|
5
|
+
export declare function getAclFilePath(aclFolder: any, aclNum: any): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
join as o
|
|
3
|
+
} from "node:path";
|
|
4
|
+
|
|
5
|
+
function t(t, n) {
|
|
6
|
+
return t + (2 < n ? "_" + n : "") + ".json";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function n(t, n, r) {
|
|
10
|
+
return o(t, "" + n, r + "_vL.txt");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function r(t, n, r) {
|
|
14
|
+
return o(t, "" + n, r + "_pM.txt");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function u(t, n, r) {
|
|
18
|
+
return o(t, "" + n, r + "_prefixPM.txt");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function e(t, n) {
|
|
22
|
+
return o(t, n + "_acl.txt");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
t as getSnapshotInfoFileName,
|
|
27
|
+
n as getVLFilePath,
|
|
28
|
+
r as getPMFilePath,
|
|
29
|
+
u as getPrefixPMFilePath,
|
|
30
|
+
e as getAclFilePath
|
|
31
|
+
};
|
package/src/QyLogFileSaver.d.ts
CHANGED
package/src/QyLogFileSaver.js
CHANGED
|
@@ -3,19 +3,19 @@ import {
|
|
|
3
3
|
} from "./QyMessager.js";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
getDefaultOptions as
|
|
6
|
+
getDefaultOptions as o
|
|
7
7
|
} from "./QyDefaultOptions.js";
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
QyLogFileSaver_Worker as
|
|
10
|
+
QyLogFileSaver_Worker as t
|
|
11
11
|
} from "./QyLogFileSaver_Worker.js";
|
|
12
12
|
|
|
13
13
|
class r extends e {
|
|
14
|
-
constructor(e, r) {
|
|
15
|
-
|
|
16
|
-
...
|
|
17
|
-
...
|
|
18
|
-
}, super(
|
|
14
|
+
constructor(e, r, s) {
|
|
15
|
+
s = {
|
|
16
|
+
...o("QyLogFileSaver"),
|
|
17
|
+
...s
|
|
18
|
+
}, super(t, [ r ], s, e);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { QyMessageWorker } from "./QyMessageWorker.ts";
|
|
2
|
+
import { QyBinWriter } from "./QyBinWriter.ts";
|
|
2
3
|
export declare class QyLogFileSaver_Worker extends QyMessageWorker {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
logFileFolder: string;
|
|
5
|
+
_dateDirPath: any;
|
|
6
|
+
timeoutRef: any;
|
|
7
|
+
qyBinWriter: QyBinWriter;
|
|
8
|
+
constructor(logFileFolder: string, options: any);
|
|
9
|
+
get dateDirPath(): any;
|
|
10
|
+
cast_save(data: any, needPromise?: boolean): any;
|
|
11
|
+
_op_start(): Promise<void>;
|
|
8
12
|
_op_stop(): Promise<void>;
|
|
13
|
+
_op_switch(): Promise<void>;
|
|
14
|
+
_switch(): any;
|
|
9
15
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
join as s
|
|
3
|
+
} from "node:path";
|
|
4
|
+
|
|
1
5
|
import {
|
|
2
6
|
getDefaultOptions as r
|
|
3
7
|
} from "./QyDefaultOptions.js";
|
|
@@ -7,29 +11,76 @@ import {
|
|
|
7
11
|
} from "./QyMessageWorker.js";
|
|
8
12
|
|
|
9
13
|
import {
|
|
10
|
-
QyBinWriter as
|
|
14
|
+
QyBinWriter as i
|
|
11
15
|
} from "./QyBinWriter.js";
|
|
12
16
|
|
|
17
|
+
import {
|
|
18
|
+
ensureDir as o
|
|
19
|
+
} from "./QyUtils.js";
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
logger as a,
|
|
23
|
+
regMsgProc as n
|
|
24
|
+
} from "./QyLogger.js";
|
|
25
|
+
|
|
13
26
|
class QyLogFileSaver_Worker extends t {
|
|
27
|
+
logFileFolder;
|
|
28
|
+
_dateDirPath;
|
|
29
|
+
timeoutRef;
|
|
14
30
|
qyBinWriter;
|
|
15
|
-
constructor(t) {
|
|
16
|
-
|
|
31
|
+
constructor(t, e) {
|
|
32
|
+
(e = {
|
|
17
33
|
...r("QyLogFileSaver_Worker"),
|
|
18
|
-
...
|
|
19
|
-
}), this.qyBinWriter = new
|
|
34
|
+
...e
|
|
35
|
+
}).append = !e.clearLogAtStart, super(e), this.logFileFolder = t, this.qyBinWriter = new i(e),
|
|
36
|
+
n(a);
|
|
20
37
|
}
|
|
21
|
-
|
|
22
|
-
this.
|
|
38
|
+
get dateDirPath() {
|
|
39
|
+
return this._dateDirPath;
|
|
23
40
|
}
|
|
24
|
-
cast_save(t) {
|
|
25
|
-
this.qyBinWriter.save(t);
|
|
41
|
+
cast_save(t, e = !1) {
|
|
42
|
+
return this.qyBinWriter.save(t, e);
|
|
26
43
|
}
|
|
27
|
-
async _op_start(
|
|
28
|
-
|
|
44
|
+
async _op_start() {
|
|
45
|
+
var {
|
|
46
|
+
qyBinWriter: t,
|
|
47
|
+
options: e
|
|
48
|
+
} = this, r = this._dateDirPath = h(this);
|
|
49
|
+
t.start(s(r, "change.txt")), await o(r), a.setFileConsoleDateDirPath(r, e.clearLogAtStart);
|
|
29
50
|
}
|
|
30
51
|
async _op_stop() {
|
|
31
|
-
|
|
52
|
+
var {
|
|
53
|
+
timeoutRef: t,
|
|
54
|
+
qyBinWriter: e
|
|
55
|
+
} = this;
|
|
56
|
+
t && (clearTimeout(t), this.timeoutRef = void 0), a.closeFileConsole(),
|
|
57
|
+
await e.stop();
|
|
32
58
|
}
|
|
59
|
+
async _op_switch() {
|
|
60
|
+
var {
|
|
61
|
+
qyBinWriter: t,
|
|
62
|
+
options: e
|
|
63
|
+
} = this, r = h(this);
|
|
64
|
+
this._dateDirPath !== r && (this._dateDirPath = r, t.switch(s(r, "change.txt")),
|
|
65
|
+
await o(r), a.setFileConsoleDateDirPath(r, e.clearLogAtStart));
|
|
66
|
+
}
|
|
67
|
+
_switch() {
|
|
68
|
+
return this.pushAndRunWithPromise([ this._op_switch ]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function h(t) {
|
|
73
|
+
var e, r, {
|
|
74
|
+
logFileFolder: i,
|
|
75
|
+
timeoutRef: o
|
|
76
|
+
} = t, o = (void 0 !== o && clearTimeout(o), new Date());
|
|
77
|
+
return t.timeoutRef = setTimeout(t._switch.bind(t), 1e3 * (60 * (60 - (t = o).getUTCMinutes()) - t.getUTCSeconds())),
|
|
78
|
+
t = i, o = (i = o).getUTCFullYear(), e = i.getUTCMonth() + 1, r = i.getUTCDate(),
|
|
79
|
+
i = i.getUTCHours(), s(t, o.toString(), l(e), l(r), l(i));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function l(t) {
|
|
83
|
+
return t.toString().padStart(2, "0");
|
|
33
84
|
}
|
|
34
85
|
|
|
35
86
|
export {
|
package/src/QyLogger.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
export declare const ThreadMark: string;
|
|
2
|
-
declare
|
|
2
|
+
export declare function regMsgProc(obj: any): void;
|
|
3
|
+
export declare function unregMsgProc(obj: any): void;
|
|
4
|
+
declare class QyLogger {
|
|
3
5
|
_level: number;
|
|
4
6
|
fileConsole: any;
|
|
5
7
|
stdout: any;
|
|
6
8
|
stderr: any;
|
|
9
|
+
outBuf: any[];
|
|
10
|
+
errBuf: any[];
|
|
11
|
+
mainBuf: any[];
|
|
7
12
|
get level(): string;
|
|
8
13
|
set level(val: string);
|
|
9
14
|
info(...argList: any[]): void;
|
|
@@ -11,20 +16,13 @@ declare class QyLoggerBase {
|
|
|
11
16
|
debug(...argList: any[]): void;
|
|
12
17
|
warn(...argList: any[]): void;
|
|
13
18
|
error(...argList: any[]): void;
|
|
14
|
-
}
|
|
15
|
-
declare class QyMainLogger extends QyLoggerBase {
|
|
16
|
-
outBuf: any[];
|
|
17
|
-
errBuf: any[];
|
|
18
|
-
mainBuf: any[];
|
|
19
19
|
closeFileConsole(): void;
|
|
20
20
|
setFileConsoleDateDirPath(dateDirPath: string, clearLogAtStart?: boolean): void;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
declare class QyWorkerLogger extends QyLoggerBase {
|
|
25
|
-
constructor();
|
|
26
|
-
handleStdOutMsg(msg: any): void;
|
|
27
|
-
handleStdErrMsg(msg: any): void;
|
|
21
|
+
post_o(...argList: any[]): void;
|
|
22
|
+
post_e(...argList: any[]): void;
|
|
23
|
+
setLogWorkerId(logWorkerId: any): void;
|
|
28
24
|
}
|
|
29
|
-
export declare
|
|
25
|
+
export declare function postMain(msgName: string, ...argList: any[]): void;
|
|
26
|
+
export declare function postThread(threadId: number, msgName: string, ...argList: any[]): Promise<void>;
|
|
27
|
+
export declare const logger: QyLogger;
|
|
30
28
|
export {};
|