Compare commits
No commits in common. "d39e13dfe1f0a1a82dbec707d31a41a0f2f3ea52" and "c58d75129de93c5c782bdc43a085f2bc42fc70aa" have entirely different histories.
d39e13dfe1
...
c58d75129d
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/nodelogging",
|
"name": "@hibas123/nodelogging",
|
||||||
"version": "3.0.6",
|
"version": "3.0.4",
|
||||||
"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.6",
|
"@hibas123/logging": "^3.0.3",
|
||||||
"@hibas123/utils": "^2.2.18"
|
"@hibas123/utils": "^2.2.18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,12 @@ const MAX_FILE_SIZE = 500000000;
|
|||||||
|
|
||||||
export class LoggingFiles implements Adapter {
|
export class LoggingFiles implements Adapter {
|
||||||
file: Files;
|
file: Files;
|
||||||
constructor(private filename: string, private maxFileSize = MAX_FILE_SIZE) {}
|
constructor(
|
||||||
|
private filename: string,
|
||||||
|
private error = false,
|
||||||
|
private maxFileSize = MAX_FILE_SIZE,
|
||||||
|
private noPrefix = false
|
||||||
|
) {}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if (!this.file) {
|
if (!this.file) {
|
||||||
@ -33,21 +38,6 @@ 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;
|
||||||
|
|
||||||
@ -67,22 +57,21 @@ 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;
|
private $initialized = false;
|
||||||
|
|
||||||
public get initlialized() {
|
public get initlialized() {
|
||||||
return this.#initialized;
|
return this.$initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructor(private file: string) {}
|
private constructor(private file: string) {}
|
||||||
|
|
||||||
public async init(maxFileSize: number) {
|
public async init(maxFileSize: number) {
|
||||||
if (this.#initialized) return;
|
if (this.$initialized) return;
|
||||||
let lock = await this.lock.getLock();
|
let lock = await this.lock.getLock();
|
||||||
this.maxFileSize == maxFileSize;
|
this.maxFileSize == maxFileSize;
|
||||||
await this.initializeFile();
|
await this.initializeFile();
|
||||||
this.#initialized = true;
|
this.$initialized = true;
|
||||||
lock.release();
|
lock.release();
|
||||||
this.checkQueue();
|
this.checkQueue();
|
||||||
}
|
}
|
||||||
@ -115,7 +104,7 @@ export class Files {
|
|||||||
this.size = size;
|
this.size = size;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
//TODO: is this the right behavior?
|
//ToDo is this the right behavior?
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,7 +129,6 @@ export class Files {
|
|||||||
Files.files.delete(this.file);
|
Files.files.delete(this.file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public flush(sync: boolean) {
|
public flush(sync: boolean) {
|
||||||
if (sync) {
|
if (sync) {
|
||||||
// if sync flush, the process most likely is in failstate, so checkQueue stopped its work.
|
// if sync flush, the process most likely is in failstate, so checkQueue stopped its work.
|
||||||
@ -177,7 +165,7 @@ export class Files {
|
|||||||
|
|
||||||
public write(data: Buffer) {
|
public write(data: Buffer) {
|
||||||
this.queue.push(data);
|
this.queue.push(data);
|
||||||
this.debounce.trigger();
|
this.checkQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public dispose() {}
|
public dispose() {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user