mirror of https://github.com/embarklabs/embark.git
refactor(@embark/process-logs-api-manager): make process-logs-api-manager handle logs for every process
This commit is contained in:
parent
42673002cc
commit
0455c550ce
|
@ -2,7 +2,6 @@ import { dappPath } from 'embark-utils';
|
|||
import { __ } from 'embark-i18n';
|
||||
const async = require('async');
|
||||
const DevTxs = require('./dev_txs');
|
||||
const ProcessLogsApi = require('embark-process-logs-api');
|
||||
const constants = require('embark-core/constants');
|
||||
|
||||
const PROCESS_NAME = 'blockchain';
|
||||
|
@ -48,7 +47,7 @@ class BlockchainListener {
|
|||
});
|
||||
|
||||
this.ipc.server.once('connect', () => {
|
||||
this.processLogsApi = new ProcessLogsApi({embark: this.embark, processName: PROCESS_NAME, silent: true});
|
||||
this.events.request('process:logs:register', {processName: PROCESS_NAME, eventName: "blockchain:log", silent: true});
|
||||
this._listenToBlockchainLogs();
|
||||
});
|
||||
if (this.ipc.isServer() && this.isDev) {
|
||||
|
@ -72,7 +71,7 @@ class BlockchainListener {
|
|||
*/
|
||||
_listenToBlockchainLogs() {
|
||||
this.ipc.on('blockchain:log', ({logLevel, message}) => {
|
||||
this.processLogsApi.logHandler.handleLog({logLevel, message});
|
||||
this.events.emit('blockchain:log', logLevel, message);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [4.1.0-beta.5](https://github.com/embark-framework/embark/compare/v4.1.0-beta.4...v4.1.0-beta.5) (2019-07-10)
|
||||
|
||||
**Note:** Version bump only for package embark-console-listener
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [4.1.0-beta.4](https://github.com/embark-framework/embark/compare/v4.1.0-beta.3...v4.1.0-beta.4) (2019-06-27)
|
||||
|
||||
**Note:** Version bump only for package embark-console-listener
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [4.1.0-beta.3](https://github.com/embark-framework/embark/compare/v4.1.0-beta.2...v4.1.0-beta.3) (2019-06-07)
|
||||
|
||||
**Note:** Version bump only for package embark-console-listener
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [4.1.0-beta.2](https://github.com/embark-framework/embark/compare/v4.1.0-beta.1...v4.1.0-beta.2) (2019-05-22)
|
||||
|
||||
**Note:** Version bump only for package embark-console-listener
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [4.1.0-beta.1](https://github.com/embark-framework/embark/compare/v4.1.0-beta.0...v4.1.0-beta.1) (2019-05-15)
|
||||
|
||||
**Note:** Version bump only for package embark-console-listener
|
|
@ -1,6 +0,0 @@
|
|||
# `embark-console-listener`
|
||||
|
||||
> Listens to Embark logs and stores them so that they can be printed in Cockpit
|
||||
|
||||
Visit [embark.status.im](https://embark.status.im/) to get started with
|
||||
[Embark](https://github.com/embark-framework/embark).
|
|
@ -1,68 +0,0 @@
|
|||
{
|
||||
"name": "embark-console-listener",
|
||||
"version": "4.1.0-beta.5",
|
||||
"author": "Iuri Matias <iuri.matias@gmail.com>",
|
||||
"contributors": [],
|
||||
"description": "Console listener component for Embark",
|
||||
"homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-console-listener#readme",
|
||||
"bugs": "https://github.com/embark-framework/embark/issues",
|
||||
"keywords": [
|
||||
"blockchain",
|
||||
"dapps",
|
||||
"ethereum",
|
||||
"ipfs",
|
||||
"serverless",
|
||||
"solc",
|
||||
"solidity"
|
||||
],
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"directory": "packages/embark-console-listener",
|
||||
"type": "git",
|
||||
"url": "https://github.com/embark-framework/embark.git"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"scripts": {
|
||||
"build": "cross-env BABEL_ENV=node babel src --extensions \".js\" --out-dir dist --root-mode upward --source-maps",
|
||||
"ci": "npm run qa",
|
||||
"clean": "npm run reset",
|
||||
"lint": "npm-run-all lint:*",
|
||||
"lint:js": "eslint src/",
|
||||
"// lint:ts": "tslint -c tslint.json \"src/**/*.ts\"",
|
||||
"package": "npm pack",
|
||||
"// qa": "npm-run-all lint typecheck build package",
|
||||
"qa": "npm-run-all lint build package",
|
||||
"reset": "npx rimraf dist embark-*.tgz package",
|
||||
"start": "npm run watch",
|
||||
"// typecheck": "tsc",
|
||||
"watch": "run-p watch:*",
|
||||
"watch:build": "npm run build -- --verbose --watch",
|
||||
"// watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "../../.eslintrc.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime-corejs2": "7.3.1",
|
||||
"embark-process-logs-api": "^4.1.0-beta.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.2.3",
|
||||
"@babel/core": "7.2.2",
|
||||
"cross-env": "5.2.0",
|
||||
"eslint": "5.7.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
"rimraf": "2.6.3",
|
||||
"source-map-support": "0.5.9",
|
||||
"tslint": "5.16.0",
|
||||
"typescript": "3.4.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.12.0 <12.0.0",
|
||||
"npm": ">=6.4.1",
|
||||
"yarn": ">=1.12.3"
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
const ProcessLogsApi = require('embark-process-logs-api');
|
||||
|
||||
const EMBARK_PROCESS_NAME = 'embark';
|
||||
|
||||
class ConsoleListener {
|
||||
constructor(embark, _options) {
|
||||
this.events = embark.events;
|
||||
this.processLogsApi = new ProcessLogsApi({embark: embark, processName: EMBARK_PROCESS_NAME, silent: false});
|
||||
|
||||
this.events.on("log", (logLevel, message) => {
|
||||
this.processLogsApi.logHandler.handleLog({logLevel, message}, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConsoleListener;
|
|
@ -30,7 +30,7 @@ export class ProcessLauncher {
|
|||
this.exitCallback = options.exitCallback;
|
||||
this.embark = options.embark;
|
||||
this.logs = [];
|
||||
this.processLogsApi = new ProcessLogsApi({embark: this.embark, processName: this.name, silent: this.silent});
|
||||
this.events.request('process:logs:register', {processName: this.name, eventName: `process:${this.name}:log`, silent: this.silent});
|
||||
|
||||
this.subscriptions = {};
|
||||
this._subscribeToMessages();
|
||||
|
@ -49,7 +49,7 @@ export class ProcessLauncher {
|
|||
self.logger.error(msg.error);
|
||||
}
|
||||
if (msg.result === constants.process.log) {
|
||||
return self.processLogsApi.logHandler.handleLog(msg);
|
||||
return this.events.emit(`process:${this.name}:log`, msg.type, msg.message);
|
||||
}
|
||||
if (msg.event) {
|
||||
return self._handleEvent(msg);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# `embark-process-logs-api`
|
||||
# `embark-process-logs-api-manager`
|
||||
|
||||
Registers APIs for Embark process logs
|
||||
Manages and registers APIs for Embark process logs
|
||||
|
||||
Visit [embark.status.im](https://embark.status.im/) to get started with
|
||||
[Embark](https://github.com/embark-framework/embark).
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"name": "embark-process-logs-api",
|
||||
"name": "embark-process-logs-api-manager",
|
||||
"version": "4.1.0-beta.5",
|
||||
"author": "Iuri Matias <iuri.matias@gmail.com>",
|
||||
"contributors": [],
|
||||
"description": "Registers APIs for Embark process logs",
|
||||
"homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-process-logs-api#readme",
|
||||
"description": "Manages and registers APIs for Embark process logs",
|
||||
"homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-process-logs-api-manager#readme",
|
||||
"bugs": "https://github.com/embark-framework/embark/issues",
|
||||
"keywords": [
|
||||
"blockchain",
|
||||
|
@ -20,7 +20,7 @@
|
|||
],
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"directory": "packages/embark-process-logs-api",
|
||||
"directory": "packages/embark-process-logs-api-manager",
|
||||
"type": "git",
|
||||
"url": "https://github.com/embark-framework/embark.git"
|
||||
},
|
|
@ -0,0 +1,52 @@
|
|||
const {escapeHtml, LogHandler} = require('embark-utils');
|
||||
|
||||
class ProcessLogsApiManager {
|
||||
constructor(embark) {
|
||||
this.embark = embark;
|
||||
this.logger = this.embark.logger;
|
||||
this.events = this.embark.events;
|
||||
|
||||
this.processHandlers = {};
|
||||
|
||||
this.events.setCommandHandler('process:logs:register', ({processName, eventName, silent, alwaysAlreadyLogged}) => {
|
||||
this.processHandlers[processName] = new LogHandler({events: this.events, logger: this.logger, processName, silent});
|
||||
this.events.on(eventName, (logLevel, message, alreadyLogged) => {
|
||||
this.processHandlers[processName].handleLog({logLevel, message}, alwaysAlreadyLogged || alreadyLogged);
|
||||
});
|
||||
});
|
||||
|
||||
this.registerAPICalls();
|
||||
}
|
||||
|
||||
registerAPICalls() {
|
||||
const apiRoute = '/embark-api/process-logs/:processName';
|
||||
this.embark.registerAPICall(
|
||||
'ws',
|
||||
apiRoute,
|
||||
(ws, req) => {
|
||||
const processName = req.params.processName;
|
||||
this.events.on(`process-log-${processName}`, (log) => {
|
||||
log.msg = escapeHtml(log.msg);
|
||||
log.msg_clear = escapeHtml(log.msg_clear);
|
||||
|
||||
ws.send(JSON.stringify(log), () => {});
|
||||
});
|
||||
}
|
||||
);
|
||||
this.embark.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/process-logs/:processName',
|
||||
(req, res) => {
|
||||
let limit = parseInt(req.query.limit, 10);
|
||||
if (!Number.isInteger(limit)) limit = 0;
|
||||
const result = this.processHandlers[req.params.processName].logs
|
||||
.slice(limit * -1)
|
||||
.map(msg => escapeHtml(msg));
|
||||
|
||||
res.send(JSON.stringify(result));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ProcessLogsApiManager;
|
|
@ -1,4 +0,0 @@
|
|||
engine-strict = true
|
||||
package-lock = false
|
||||
save-exact = true
|
||||
scripts-prepend-node-path = true
|
|
@ -1,46 +0,0 @@
|
|||
const {escapeHtml, LogHandler} = require('embark-utils');
|
||||
|
||||
// TODO: looks unnecessary, should be moved to a common module together with embark-listener
|
||||
|
||||
class ProcessLogsApi {
|
||||
constructor({embark, processName, silent}) {
|
||||
this.embark = embark;
|
||||
this.processName = processName;
|
||||
this.logger = this.embark.logger;
|
||||
this.events = this.embark.events;
|
||||
this.logHandler = new LogHandler({events: this.events, logger: this.logger, processName: this.processName, silent});
|
||||
|
||||
this.registerAPICalls();
|
||||
}
|
||||
|
||||
registerAPICalls() {
|
||||
const apiRoute = '/embark-api/process-logs/' + this.processName;
|
||||
this.embark.registerAPICall(
|
||||
'ws',
|
||||
apiRoute,
|
||||
(ws, _req) => {
|
||||
this.events.on('process-log-' + this.processName, function (log) {
|
||||
log.msg = escapeHtml(log.msg);
|
||||
log.msg_clear = escapeHtml(log.msg_clear);
|
||||
|
||||
ws.send(JSON.stringify(log), () => {});
|
||||
});
|
||||
}
|
||||
);
|
||||
this.embark.registerAPICall(
|
||||
'get',
|
||||
'/embark-api/process-logs/' + this.processName,
|
||||
(req, res) => {
|
||||
let limit = parseInt(req.query.limit, 10);
|
||||
if (!Number.isInteger(limit)) limit = 0;
|
||||
const result = this.logHandler.logs
|
||||
.slice(limit * -1)
|
||||
.map(msg => escapeHtml(msg));
|
||||
|
||||
res.send(JSON.stringify(result));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ProcessLogsApi;
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src/**/*"]
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"extends": "../../tslint.json"
|
||||
}
|
|
@ -113,6 +113,9 @@ class TransactionLogger {
|
|||
let dataObject;
|
||||
if (method === blockchainConstants.transactionMethods.eth_getTransactionReceipt) {
|
||||
dataObject = args.respData.result;
|
||||
if (!dataObject) {
|
||||
return;
|
||||
}
|
||||
if (this.transactions[args.respData.result.transactionHash]) {
|
||||
// This is the normal case. If we don't get here, it's because we missed a TX
|
||||
dataObject = Object.assign(dataObject, this.transactions[args.respData.result.transactionHash]);
|
||||
|
|
|
@ -100,7 +100,6 @@
|
|||
"embark-code-runner": "^4.1.0-beta.5",
|
||||
"embark-compiler": "^4.1.0-beta.3",
|
||||
"embark-console": "^4.1.0-beta.5",
|
||||
"embark-console-listener": "^4.1.0-beta.5",
|
||||
"embark-contracts-manager": "^4.1.0-beta.5",
|
||||
"embark-core": "^4.1.0-beta.5",
|
||||
"embark-coverage": "^4.1.0-beta.5",
|
||||
|
@ -117,7 +116,7 @@
|
|||
"embark-namesystem": "^4.1.0-beta.5",
|
||||
"embark-pipeline": "^4.1.0-beta.5",
|
||||
"embark-plugin-cmd": "^4.1.0-beta.5",
|
||||
"embark-process-logs-api": "^4.1.0-beta.5",
|
||||
"embark-process-logs-api-manager": "^4.1.0-beta.5",
|
||||
"embark-profiler": "^4.1.0-beta.3",
|
||||
"embark-proxy": "^4.1.0-beta.5",
|
||||
"embark-reset": "^4.1.0-beta.3",
|
||||
|
|
|
@ -180,7 +180,7 @@ class EmbarkController {
|
|||
});
|
||||
});
|
||||
|
||||
let plugin = engine.plugins.createPlugin('cmdcontrollerplugin', {});
|
||||
const plugin = engine.plugins.createPlugin('cmdcontrollerplugin', {});
|
||||
plugin.registerActionForEvent("embark:engine:started", async (_params, cb) => {
|
||||
try {
|
||||
await Promise.all([
|
||||
|
|
|
@ -4,6 +4,8 @@ const async = require('async');
|
|||
const utils = require('../utils/utils');
|
||||
const Logger = require('embark-logger');
|
||||
|
||||
const EMBARK_PROCESS_NAME = 'embark';
|
||||
|
||||
class Engine {
|
||||
constructor(options) {
|
||||
this.env = options.env;
|
||||
|
@ -166,6 +168,7 @@ class Engine {
|
|||
this.registerModulePackage('embark-storage');
|
||||
this.registerModule('communication');
|
||||
this.registerModulePackage('embark-namesystem');
|
||||
this.registerModulePackage('embark-process-logs-api-manager');
|
||||
}
|
||||
|
||||
blockchainComponents() {
|
||||
|
@ -212,7 +215,6 @@ class Engine {
|
|||
this.registerModulePackage('embark-web3');
|
||||
this.registerModulePackage('embark-accounts-manager');
|
||||
this.registerModulePackage('embark-specialconfigs', {plugins: this.plugins});
|
||||
this.registerModulePackage('embark-console-listener');
|
||||
this.registerModulePackage('embark-transaction-logger');
|
||||
}
|
||||
|
||||
|
@ -388,6 +390,8 @@ class Engine {
|
|||
cockpitModules() {
|
||||
this.registerModulePackage('embark-authenticator', {singleUseAuthToken: this.singleUseAuthToken});
|
||||
this.registerModulePackage('embark-api', {plugins: this.plugins});
|
||||
// Register logs for the cockpit console
|
||||
this.events.request('process:logs:register', {processName: EMBARK_PROCESS_NAME, eventName: "log", silent: false, alwaysAlreadyLogged: true});
|
||||
}
|
||||
|
||||
webServerService() {
|
||||
|
|
Loading…
Reference in New Issue