embark/lib/logger.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-08-22 03:40:05 +00:00
var colors = require('colors');
2016-09-17 03:56:25 +00:00
var Logger = function(options) {
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
this.logLevel = options.logLevel || 'info';
this.logFunction = options.logFunction || console.log;
this.contractsState = options.contractsState || console.log;
this.availableServices = options.availableServices || console.log;
2016-09-17 03:56:25 +00:00
};
2016-08-22 03:40:05 +00:00
2016-09-17 03:56:25 +00:00
Logger.prototype.error = function(txt) {
if (!(this.shouldLog('error'))) { return; }
this.logFunction(txt.red);
};
2016-08-22 03:40:05 +00:00
2016-09-17 03:56:25 +00:00
Logger.prototype.warn = function(txt) {
if (!(this.shouldLog('warn'))) { return; }
this.logFunction(txt.yellow);
};
2016-08-22 03:40:05 +00:00
2016-09-17 03:56:25 +00:00
Logger.prototype.info = function(txt) {
if (!(this.shouldLog('info'))) { return; }
this.logFunction(txt.green);
};
2016-08-22 03:40:05 +00:00
2016-09-17 03:56:25 +00:00
Logger.prototype.debug = function(txt) {
if (!(this.shouldLog('debug'))) { return; }
this.logFunction(txt);
};
Logger.prototype.trace = function(txt) {
if (!(this.shouldLog('trace'))) { return; }
this.logFunction(txt);
};
2016-08-22 03:40:05 +00:00
2016-09-17 03:56:25 +00:00
Logger.prototype.shouldLog = function(level) {
return (this.logLevels.indexOf(level) <= this.logLevels.indexOf(this.logLevel));
2016-08-22 03:40:05 +00:00
};
module.exports = Logger;