From c1d258b819b4e94631ca21218f51d99857a36465 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 15 Mar 2018 16:44:05 -0400 Subject: [PATCH] add events to logger --- lib/core/engine.js | 2 +- lib/core/logger.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/core/engine.js b/lib/core/engine.js index bdbb8d36..53ee6203 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -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; diff --git a/lib/core/logger.js b/lib/core/logger.js index 8eddd836..361e662f 100644 --- a/lib/core/logger.js +++ b/lib/core/logger.js @@ -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); };