move logger api call into logger

This commit is contained in:
Iuri Matias 2018-03-13 06:57:02 -04:00
parent 3d5ceb74be
commit cfc7266415
3 changed files with 18 additions and 8 deletions

View File

@ -34,6 +34,7 @@ class Engine {
if (this.interceptLogs || this.interceptLogs === undefined) {
this.doInterceptLogs();
}
this.logger.registerAPICall(this.plugins);
}
doInterceptLogs() {

View File

@ -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;
}

View File

@ -38,12 +38,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]);