first commit

This commit is contained in:
Francois Klieber committed 2021-06-06 20:25:14 +02:00
commit aa7869eb33
386 files changed
+69375

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
const fs = require('fs');
const _ = require('lodash');
const BASEPATH = __dirname + '/../../logs/';
const Logger = function(id) {
this.fileName = `${id}.log`;
this.writing = false;
this.queue = [];
_.bindAll(this);
}
Logger.prototype.write = function(line) {
if(!this.writing) {
this.writing = true;
fs.appendFile(
BASEPATH + this.fileName,
line + '\n',
this.handleWriteCallback
);
} else
this.queue.push(line);
}
Logger.prototype.handleWriteCallback = function(err) {
if(err)
console.error(`ERROR WRITING LOG FILE ${this.fileName}:`, err);
this.writing = false;
if(_.size(this.queue))
this.write(this.queue.shift())
}
module.exports = Logger;