2017-12-14 00:49:05 +00:00
|
|
|
require('colors');
|
2016-10-02 20:57:13 +00:00
|
|
|
|
|
|
|
// TODO: just logFunction changes, probably doesn't need a whole new module just
|
|
|
|
// for this
|
2017-03-30 11:12:39 +00:00
|
|
|
class TestLogger {
|
|
|
|
constructor(options) {
|
|
|
|
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
|
|
|
|
this.logLevel = options.logLevel || 'info';
|
|
|
|
}
|
|
|
|
|
|
|
|
logFunction() {
|
2018-06-13 13:44:19 +00:00
|
|
|
console.log(...arguments);
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
error(txt) {
|
|
|
|
if (!(this.shouldLog('error'))) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-20 19:54:47 +00:00
|
|
|
console.error(txt);
|
2017-03-30 11:12:39 +00:00
|
|
|
this.logFunction(txt.red);
|
|
|
|
}
|
|
|
|
|
|
|
|
warn(txt) {
|
|
|
|
if (!(this.shouldLog('warn'))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.logFunction(txt.yellow);
|
|
|
|
}
|
|
|
|
|
|
|
|
info(txt) {
|
|
|
|
if (!(this.shouldLog('info'))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.logFunction(txt.green);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(txt) {
|
|
|
|
if (!(this.shouldLog('debug'))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.logFunction(txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
trace(txt) {
|
|
|
|
if (!(this.shouldLog('trace'))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.logFunction(txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldLog(level) {
|
|
|
|
return (this.logLevels.indexOf(level) <= this.logLevels.indexOf(this.logLevel));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-10-02 20:57:13 +00:00
|
|
|
|
|
|
|
module.exports = TestLogger;
|