mirror of
https://git.stamm.me/OpenServer/NodeLogging.git
synced 2024-11-24 06:19:23 +00:00
Add another strategy to logging, which reduces memory leak risk
This commit is contained in:
parent
0742490527
commit
d39e13dfe1
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hibas123/nodelogging",
|
||||
"version": "3.0.5",
|
||||
"version": "3.0.6",
|
||||
"description": "",
|
||||
"main": "out/index.js",
|
||||
"types": "out/index.d.ts",
|
||||
@ -32,7 +32,7 @@
|
||||
"typescript": "^4.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hibas123/logging": "^3.0.5",
|
||||
"@hibas123/logging": "^3.0.6",
|
||||
"@hibas123/utils": "^2.2.18"
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,21 @@ export class LoggingFiles implements Adapter {
|
||||
|
||||
//TODO: Optimise write path
|
||||
|
||||
const Debounce = (callback: () => void, iv = 500) => {
|
||||
let to: any;
|
||||
|
||||
return {
|
||||
trigger: () => {
|
||||
if (!to) {
|
||||
to = setTimeout(() => {
|
||||
to = undefined;
|
||||
callback();
|
||||
}, iv);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export class Files {
|
||||
private open = 0;
|
||||
|
||||
@ -52,9 +67,9 @@ export class Files {
|
||||
private size: number = 0;
|
||||
private stream: fs.WriteStream = undefined;
|
||||
private lock = new Lock();
|
||||
private debounce = Debounce(() => this.checkQueue);
|
||||
|
||||
#initialized = false;
|
||||
#iv: any;
|
||||
|
||||
public get initlialized() {
|
||||
return this.#initialized;
|
||||
@ -68,7 +83,6 @@ export class Files {
|
||||
this.maxFileSize == maxFileSize;
|
||||
await this.initializeFile();
|
||||
this.#initialized = true;
|
||||
this.#iv = setInterval(() => this.checkQueue(), 500);
|
||||
lock.release();
|
||||
this.checkQueue();
|
||||
}
|
||||
@ -122,7 +136,6 @@ export class Files {
|
||||
await this.flush(false);
|
||||
this.open--;
|
||||
if (this.open <= 0) {
|
||||
clearInterval(this.#iv);
|
||||
this.stream.close();
|
||||
Files.files.delete(this.file);
|
||||
}
|
||||
@ -164,6 +177,7 @@ export class Files {
|
||||
|
||||
public write(data: Buffer) {
|
||||
this.queue.push(data);
|
||||
this.debounce.trigger();
|
||||
}
|
||||
|
||||
public dispose() {}
|
||||
|
Loading…
Reference in New Issue
Block a user