embark-area-51/lib/core/test_logger.js

66 lines
1.1 KiB
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.logs = [];
this.logLevel = options.logLevel || 'info';
}
logFunction() {
this.logs.push(arguments);
}
contractsState() {
this.logs.push(arguments);
}
availableServices() {
this.logs.push(arguments);
}
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;