add events to logger
This commit is contained in:
parent
89616537b8
commit
c1d258b819
|
@ -23,7 +23,7 @@ class Engine {
|
|||
let self = this;
|
||||
let options = _options || {};
|
||||
this.events = new Events();
|
||||
this.logger = options.logger || new Logger({logLevel: options.logLevel || 'debug', logfile: this.logfile});
|
||||
this.logger = options.logger || new Logger({logLevel: options.logLevel || 'debug', events: this.events, logfile: this.logfile});
|
||||
this.config = new Config({env: this.env, logger: this.logger, events: this.events});
|
||||
this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs});
|
||||
this.plugins = this.config.plugins;
|
||||
|
|
|
@ -3,6 +3,7 @@ let fs = require('./fs.js');
|
|||
|
||||
class Logger {
|
||||
constructor(options) {
|
||||
this.events = options.events;
|
||||
this.logLevels = ['error', 'warn', 'info', 'debug', 'trace'];
|
||||
this.logLevel = options.logLevel || 'info';
|
||||
this.logFunction = options.logFunction || console.log;
|
||||
|
@ -22,6 +23,7 @@ Logger.prototype.error = function (txt) {
|
|||
if (!txt || !(this.shouldLog('error'))) {
|
||||
return;
|
||||
}
|
||||
this.events.emit("log", "error", txt);
|
||||
this.logFunction(txt.red);
|
||||
this.writeToFile("[error]: " + txt);
|
||||
};
|
||||
|
@ -30,6 +32,7 @@ Logger.prototype.warn = function (txt) {
|
|||
if (!txt || !(this.shouldLog('warn'))) {
|
||||
return;
|
||||
}
|
||||
this.events.emit("log", "warning", txt);
|
||||
this.logFunction(txt.yellow);
|
||||
this.writeToFile("[warning]: " + txt);
|
||||
};
|
||||
|
@ -38,6 +41,7 @@ Logger.prototype.info = function (txt) {
|
|||
if (!txt || !(this.shouldLog('info'))) {
|
||||
return;
|
||||
}
|
||||
this.events.emit("log", "info", txt);
|
||||
this.logFunction(txt.green);
|
||||
this.writeToFile("[info]: " + txt);
|
||||
};
|
||||
|
@ -46,6 +50,7 @@ Logger.prototype.debug = function (txt) {
|
|||
if (!txt || !(this.shouldLog('debug'))) {
|
||||
return;
|
||||
}
|
||||
this.events.emit("log", "debug", txt);
|
||||
this.logFunction(txt);
|
||||
this.writeToFile("[debug]: " + txt);
|
||||
};
|
||||
|
@ -54,6 +59,7 @@ Logger.prototype.trace = function (txt) {
|
|||
if (!txt || !(this.shouldLog('trace'))) {
|
||||
return;
|
||||
}
|
||||
this.events.emit("log", "trace", txt);
|
||||
this.logFunction(txt);
|
||||
this.writeToFile("[trace]: " + txt);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue