enable logger to log multiple arguments

This commit is contained in:
Jonathan Rainville 2018-06-19 14:06:56 -04:00 committed by Iuri Matias
parent c3d2ef07e8
commit 8ecd382a1f
1 changed files with 27 additions and 27 deletions

View File

@ -11,57 +11,57 @@ class Logger {
} }
} }
Logger.prototype.writeToFile = function (txt) { Logger.prototype.writeToFile = function () {
if (!this.logFile) { if (!this.logFile) {
return; return;
} }
fs.appendFileSync(this.logFile, "\n" + txt); fs.appendFileSync(this.logFile, "\n" + Array.from(arguments).join(' '));
}; };
Logger.prototype.error = function (txt) { Logger.prototype.error = function () {
if (!txt || !(this.shouldLog('error'))) { if (!arguments.length || !(this.shouldLog('error'))) {
return; return;
} }
this.events.emit("log", "error", txt); this.events.emit("log", "error", ...arguments);
this.logFunction(txt.red); this.logFunction(...Array.from(arguments).map(t => t.red));
this.writeToFile("[error]: " + txt); this.writeToFile("[error]: ", ...arguments);
}; };
Logger.prototype.warn = function (txt) { Logger.prototype.warn = function () {
if (!txt || !(this.shouldLog('warn'))) { if (!arguments.length || !(this.shouldLog('warn'))) {
return; return;
} }
this.events.emit("log", "warning", txt); this.events.emit("log", "warning", ...arguments);
this.logFunction(txt.yellow); this.logFunction(...Array.from(arguments).map(t => t.yellow));
this.writeToFile("[warning]: " + txt); this.writeToFile("[warning]: ", ...arguments);
}; };
Logger.prototype.info = function (txt) { Logger.prototype.info = function () {
if (!txt || !(this.shouldLog('info'))) { if (!arguments.length || !(this.shouldLog('info'))) {
return; return;
} }
this.events.emit("log", "info", txt); this.events.emit("log", "info", ...arguments);
this.logFunction(txt.green); this.logFunction(...Array.from(arguments).map(t => t.green));
this.writeToFile("[info]: " + txt); this.writeToFile("[info]: ", ...arguments);
}; };
Logger.prototype.debug = function (txt) { Logger.prototype.debug = function () {
if (!txt || !(this.shouldLog('debug'))) { if (!arguments.length || !(this.shouldLog('debug'))) {
return; return;
} }
this.events.emit("log", "debug", txt); this.events.emit("log", "debug", ...arguments);
this.logFunction(txt); this.logFunction(...arguments);
this.writeToFile("[debug]: " + txt); this.writeToFile("[debug]: ", ...arguments);
}; };
Logger.prototype.trace = function (txt) { Logger.prototype.trace = function () {
if (!txt || !(this.shouldLog('trace'))) { if (!arguments.length || !(this.shouldLog('trace'))) {
return; return;
} }
this.events.emit("log", "trace", txt); this.events.emit("log", "trace", ...arguments);
this.logFunction(txt); this.logFunction(...arguments);
this.writeToFile("[trace]: " + txt); this.writeToFile("[trace]: ", ...arguments);
}; };
Logger.prototype.dir = function (txt) { Logger.prototype.dir = function (txt) {