mirror of
https://git.hibas.dev/OpenServer/NodeLogging.git
synced 2025-07-01 20:51:07 +00:00
Adding initialization on first write
This commit is contained in:
10
src/index.ts
10
src/index.ts
@ -59,6 +59,8 @@ export class LoggingBase {
|
||||
private config: LoggingBaseOptions;
|
||||
private writeLock = new Lock();
|
||||
|
||||
private setted_up = false;
|
||||
|
||||
private fileStream: fs.WriteStream;
|
||||
private errorStream: fs.WriteStream;
|
||||
private fileSize: number = 0;
|
||||
@ -83,7 +85,11 @@ export class LoggingBase {
|
||||
logfile: "./logs/all.log",
|
||||
errorfile: "./logs/error.log"
|
||||
}, options);
|
||||
this.setup();
|
||||
|
||||
for (let key in this) {
|
||||
if (typeof this[key] === "function") this[key] = (<any>this[key]).bind(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
get console_out() {
|
||||
@ -99,6 +105,7 @@ export class LoggingBase {
|
||||
}
|
||||
|
||||
private async setup() {
|
||||
this.setted_up = true;
|
||||
let lock = await this.writeLock.getLock();
|
||||
if (this.config.logfile) {
|
||||
let f = await this.initializeFile(this.config.logfile, true);
|
||||
@ -213,6 +220,7 @@ export class LoggingBase {
|
||||
try {
|
||||
if (this.writeLock.locked) return;
|
||||
if (this.queue.length <= 0) return;
|
||||
if (!this.setted_up) return this.setup();
|
||||
let lock = await this.writeLock.getLock();
|
||||
var message = this.queue.shift();
|
||||
message.message += "\n";
|
||||
|
Reference in New Issue
Block a user