mirror of
https://git.stamm.me/OpenServer/NodeLogging.git
synced 2024-11-15 02:01:04 +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",
|
"name": "@hibas123/nodelogging",
|
||||||
"version": "3.0.5",
|
"version": "3.0.6",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "out/index.js",
|
"main": "out/index.js",
|
||||||
"types": "out/index.d.ts",
|
"types": "out/index.d.ts",
|
||||||
@ -32,7 +32,7 @@
|
|||||||
"typescript": "^4.2.4"
|
"typescript": "^4.2.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hibas123/logging": "^3.0.5",
|
"@hibas123/logging": "^3.0.6",
|
||||||
"@hibas123/utils": "^2.2.18"
|
"@hibas123/utils": "^2.2.18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,21 @@ export class LoggingFiles implements Adapter {
|
|||||||
|
|
||||||
//TODO: Optimise write path
|
//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 {
|
export class Files {
|
||||||
private open = 0;
|
private open = 0;
|
||||||
|
|
||||||
@ -52,9 +67,9 @@ export class Files {
|
|||||||
private size: number = 0;
|
private size: number = 0;
|
||||||
private stream: fs.WriteStream = undefined;
|
private stream: fs.WriteStream = undefined;
|
||||||
private lock = new Lock();
|
private lock = new Lock();
|
||||||
|
private debounce = Debounce(() => this.checkQueue);
|
||||||
|
|
||||||
#initialized = false;
|
#initialized = false;
|
||||||
#iv: any;
|
|
||||||
|
|
||||||
public get initlialized() {
|
public get initlialized() {
|
||||||
return this.#initialized;
|
return this.#initialized;
|
||||||
@ -68,7 +83,6 @@ export class Files {
|
|||||||
this.maxFileSize == maxFileSize;
|
this.maxFileSize == maxFileSize;
|
||||||
await this.initializeFile();
|
await this.initializeFile();
|
||||||
this.#initialized = true;
|
this.#initialized = true;
|
||||||
this.#iv = setInterval(() => this.checkQueue(), 500);
|
|
||||||
lock.release();
|
lock.release();
|
||||||
this.checkQueue();
|
this.checkQueue();
|
||||||
}
|
}
|
||||||
@ -122,7 +136,6 @@ export class Files {
|
|||||||
await this.flush(false);
|
await this.flush(false);
|
||||||
this.open--;
|
this.open--;
|
||||||
if (this.open <= 0) {
|
if (this.open <= 0) {
|
||||||
clearInterval(this.#iv);
|
|
||||||
this.stream.close();
|
this.stream.close();
|
||||||
Files.files.delete(this.file);
|
Files.files.delete(this.file);
|
||||||
}
|
}
|
||||||
@ -164,6 +177,7 @@ export class Files {
|
|||||||
|
|
||||||
public write(data: Buffer) {
|
public write(data: Buffer) {
|
||||||
this.queue.push(data);
|
this.queue.push(data);
|
||||||
|
this.debounce.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose() {}
|
public dispose() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user