Доработки Logger

This commit is contained in:
Book Pauk
2022-12-14 20:06:56 +07:00
parent 0ee373c1f3
commit 23a9e9154b

View File

@@ -48,8 +48,12 @@ class BaseLog {
this.outputBufferLength = 0; this.outputBufferLength = 0;
this.outputBuffer = []; this.outputBuffer = [];
await this.flushImpl(this.data) try {
.catch(e => { console.error(`Logger error: ${e}`); ayncExit.exit(1); } ); await this.flushImpl(this.data);
} catch (e) {
console.error(`Logger error: ${e}`);
ayncExit.exit(1);
}
this.flushing = false; this.flushing = false;
} }
@@ -112,10 +116,14 @@ class FileLog extends BaseLog {
if (this.closed) if (this.closed)
return; return;
await super.close(); await super.close();
if (this.fd) { if (this.fd) {
while (this.flushing)
await sleep(1);
await fs.close(this.fd); await fs.close(this.fd);
this.fd = null; this.fd = null;
} }
if (this.rcid) if (this.rcid)
clearTimeout(this.rcid); clearTimeout(this.rcid);
} }
@@ -151,15 +159,21 @@ class FileLog extends BaseLog {
if (this.closed) if (this.closed)
return; return;
if (!this.rcid) { this.flushing = true;
await this.doFileRotationIfNeeded(); try {
this.rcid = setTimeout(() => { if (!this.rcid) {
this.rcid = 0; await this.doFileRotationIfNeeded();
}, LOG_ROTATE_FILE_CHECK_INTERVAL); this.rcid = setTimeout(() => {
} this.rcid = 0;
}, LOG_ROTATE_FILE_CHECK_INTERVAL);
}
if (this.fd) if (this.fd) {
await fs.write(this.fd, Buffer.from(data.join(''))); await fs.write(this.fd, Buffer.from(data.join('')));
}
} finally {
this.flushing = false;
}
} }
} }