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

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-03-29 17:50:05 +00:00
let colors = 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-29 17:50:05 +00:00
let TestLogger = function(options) {
2016-10-02 20:57:13 +00:00
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
this.logs = [];
this.logLevel = options.logLevel || 'info';
};
TestLogger.prototype.logFunction = function() {
this.logs.push(arguments);
};
TestLogger.prototype.contractsState = function() {
this.logs.push(arguments);
};
TestLogger.prototype.availableServices = function() {
this.logs.push(arguments);
};
TestLogger.prototype.error = function(txt) {
if (!(this.shouldLog('error'))) { return; }
this.logFunction(txt.red);
};
TestLogger.prototype.warn = function(txt) {
if (!(this.shouldLog('warn'))) { return; }
this.logFunction(txt.yellow);
};
TestLogger.prototype.info = function(txt) {
if (!(this.shouldLog('info'))) { return; }
this.logFunction(txt.green);
};
TestLogger.prototype.debug = function(txt) {
if (!(this.shouldLog('debug'))) { return; }
this.logFunction(txt);
};
TestLogger.prototype.trace = function(txt) {
if (!(this.shouldLog('trace'))) { return; }
this.logFunction(txt);
};
TestLogger.prototype.shouldLog = function(level) {
return (this.logLevels.indexOf(level) <= this.logLevels.indexOf(this.logLevel));
};
module.exports = TestLogger;