mirror of https://github.com/embarklabs/embark.git
fix: blockchain logs show in cockpit (#1367)
This commit is contained in:
parent
891174eda3
commit
41256cfb00
|
@ -118,6 +118,7 @@ class IPC {
|
|||
cb = cb || (() => {});
|
||||
return cb();
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
this.once(action, cb);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ const PROCESS_NAME = 'blockchain';
|
|||
* BlockchainListener has two functions:
|
||||
* 1. Register API endpoints (HTTP GET and WS) to retrieve blockchain logs
|
||||
* when in standalone mode (ie `embark blockchain`).
|
||||
* 2. Listen to log events from the IPC connection (to `embark blockchain`)
|
||||
* 2. Listen to log events from the IPC connection (to `embark blockchain`)
|
||||
* and ensure they are processed through the LogHandler.
|
||||
*/
|
||||
class BlockchainListener {
|
||||
|
@ -22,20 +22,20 @@ class BlockchainListener {
|
|||
this.events = embark.events;
|
||||
this.logger = embark.logger;
|
||||
this.ipc = ipc;
|
||||
this.processLogsApi = new ProcessLogsApi({embark: this.embark, processName: PROCESS_NAME, silent: true});
|
||||
|
||||
if (this.ipc.isServer()) {
|
||||
this.ipc.server.once('connect', () => {
|
||||
this.processLogsApi = new ProcessLogsApi({embark: this.embark, processName: PROCESS_NAME, silent: true});
|
||||
this._listenToBlockchainLogs();
|
||||
this._listenToCommands();
|
||||
this._registerConsoleCommands();
|
||||
this._registerApiEndpoint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens to log events emitted by the standalone blockchain and ensures
|
||||
* they are processed through the LogHandler.
|
||||
*
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
_listenToBlockchainLogs() {
|
||||
|
|
|
@ -120,11 +120,15 @@ var Blockchain = function(userConfig, clientClass) {
|
|||
*/
|
||||
Blockchain.prototype.initStandaloneProcess = function () {
|
||||
if (this.isStandalone) {
|
||||
let logQueue = [];
|
||||
|
||||
// on every log logged in logger (say that 3x fast), send the log
|
||||
// to the IPC serve listening (only if we're connected of course)
|
||||
this.logger.events.on('log', (logLevel, message) => {
|
||||
if (this.ipc.connected) {
|
||||
this.ipc.request('blockchain:log', {logLevel, message});
|
||||
} else {
|
||||
logQueue.push({logLevel, message});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -135,10 +139,13 @@ Blockchain.prototype.initStandaloneProcess = function () {
|
|||
// `embark run` without restarting `embark blockchain`)
|
||||
setInterval(() => {
|
||||
if (!this.ipc.connected) {
|
||||
this.ipc.connect(() => {
|
||||
this.ipc.connect(() => {
|
||||
if (this.ipc.connected) {
|
||||
this.ipc.listenTo('regularTxs', (mode) => {
|
||||
if(mode === 'start') this.startRegularTxs(() => {});
|
||||
logQueue.forEach(message => { this.ipc.request('blockchain:log', message); });
|
||||
logQueue = [];
|
||||
|
||||
this.ipc.listenTo('regularTxs', (mode) => {
|
||||
if(mode === 'start') this.startRegularTxs(() => {});
|
||||
else if (mode === 'stop') this.stopRegularTxs(() => {});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue