From 977db1d94573ed31bab79369ed0e8cb305961699 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 13 Mar 2018 06:57:02 -0400 Subject: [PATCH] move logger api call into logger --- lib/core/logger.js | 19 +++++++++++++++++-- lib/modules/webserver/server.js | 6 ------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/core/logger.js b/lib/core/logger.js index ca3659e0..d7ad166d 100644 --- a/lib/core/logger.js +++ b/lib/core/logger.js @@ -11,8 +11,23 @@ class Logger { } } -Logger.prototype.writeToFile = function () { - if (!this.logFile) { +Logger.prototype.registerAPICall = function (plugins) { + const self = this; + + let plugin = plugins.createPlugin('dashboard', {}); + plugin.registerAPICall( + 'ws', + '/embark/logs', + (ws, req) => { + self.events.on("log", function(logLevel, logMsg) { + ws.send(JSON.stringify({msg: logMsg, msg_clear: logMsg.stripColors, logLevel: logLevel}), () => {}); + }); + } + ); +}; + +Logger.prototype.writeToFile = function (txt) { + if (!this.logfile) { return; } diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index f86979f9..ca2929e4 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -36,12 +36,6 @@ class Server { expressWebSocket(app); - app.ws('/embark/logs', function(ws, req) { - self.events.on("log", function(logLevel, logMsg) { - ws.send(JSON.stringify({msg: logMsg, msg_clear: logMsg.stripColors, logLevel: logLevel}), () => {}); - }); - }); - let apiCalls = self.plugins.getPluginsProperty("apiCalls", "apiCalls"); for (let apiCall of apiCalls) { app[apiCall.method].apply(app, [apiCall.endpoint, apiCall.cb]);