embark/lib/utils/test_logger.js

57 lines
1011 B
JavaScript
Raw Normal View History

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() {
console.log(...arguments);
2017-03-30 11:12:39 +00:00
}
error(txt) {
if (!(this.shouldLog('error'))) {
return;
}
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;