adds dashboard logging for: geth, ipfs, swarm

This commit is contained in:
Moksh Jain 2018-09-16 00:18:53 +05:30 committed by Pascal Precht
parent 960cd0f792
commit 51b2cce0ea
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
5 changed files with 110 additions and 0 deletions

View File

@ -52,6 +52,14 @@ class BlockchainProcessLauncher {
this.blockchainProcess.kill();
});
this.events.on('logs:ethereum:enable', () => {
this.blockchainProcess.silent = false;
});
this.events.on('logs:ethereum:disable', () => {
this.blockchainProcess.silent = true;
});
this.events.on('exit', () => {
this.blockchainProcess.send('exit');
});

View File

@ -24,6 +24,8 @@ class BlockchainModule {
self.assertNodeConnection(true, (connected) => {
if (connected) return cb();
self.startBlockchainNode(cb);
this.listenToCommands();
this.registerConsoleCommands();
});
});
@ -33,6 +35,35 @@ class BlockchainModule {
});
}
listenToCommands() {
this.events.setCommandHandler('logs:ethereum:turnOn', (cb) => {
this.events.emit('logs:ethereum:enable');
return cb(null, 'Enabling Geth logs');
});
this.events.setCommandHandler('logs:ethereum:turnOff', (cb) => {
this.events.emit('logs:ethereum:disable');
return cb(null, 'Disabling Geth logs');
});
}
registerConsoleCommands() {
const self = this;
self.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => cmd === 'log geth on',
process: (cb) => self.events.request('logs:ethereum:turnOn', cb)
};
});
self.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => cmd === 'log geth off',
process: (cb) => self.events.request('logs:ethereum:turnOff', cb)
};
});
}
assertNodeConnection(noLogs, cb) {
if (typeof noLogs === 'function') {
cb = noLogs;

View File

@ -31,6 +31,8 @@ class IPFS {
return;
}
self.logger.info("IPFS node not found, attempting to start own node");
this.listenToCommands();
this.registerConsoleCommands();
self.startProcess(() => {});
});
}
@ -133,6 +135,35 @@ class IPFS {
});
}
listenToCommands() {
this.events.setCommandHandler('logs:ipfs:turnOn', (cb) => {
this.events.emit('logs:storage:enable');
return cb(null, 'Enabling IPFS logs');
});
this.events.setCommandHandler('logs:ipfs:turnOff', (cb) => {
this.events.emit('logs:storage:disable');
return cb(null, 'Disabling IPFS logs');
});
}
registerConsoleCommands() {
const self = this;
self.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => cmd === 'log ipfs on',
process: (cb) => self.events.request('logs:ipfs:turnOn', cb)
};
});
self.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => cmd === 'log ipfs off',
process: (cb) => self.events.request('logs:ipfs:turnOff', cb)
};
});
}
isIpfsStorageEnabledInTheConfig() {
let {enabled, available_providers, dappConnection} = this.storageConfig;
return enabled && (available_providers.indexOf('ipfs') > 0 || dappConnection.find(c => c.provider === 'ipfs'));

View File

@ -126,6 +126,15 @@ class StorageProcessesLauncher {
self.logger.info(__(`${storageName} process started`).cyan);
callback();
});
self.events.on('logs:swarm:enable', () => {
self.processes[storageName].silent = false;
});
self.events.on('logs:swarm:disable', () => {
self.processes[storageName].silent = true;
});
});
}
}

View File

@ -43,6 +43,8 @@ class Swarm {
return;
}
this.logger.info("SWARM: Swarm node not found, attempting to start own node");
this.listenToCommands();
this.registerConsoleCommands();
return this.startProcess(() => {});
});
});
@ -116,6 +118,35 @@ class Swarm {
});
}
listenToCommands() {
this.events.setCommandHandler('logs:swarm:turnOn', (cb) => {
this.events.emit('logs:storage:enable');
return cb(null, 'Enabling Swarm logs');
});
this.events.setCommandHandler('logs:swarm:turnOff', (cb) => {
this.events.emit('logs:storage:disable');
return cb(null, 'Disabling Swarm logs');
});
}
registerConsoleCommands() {
const self = this;
self.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => cmd === 'log swarm on',
process: (cb) => self.events.request('logs:swarm:turnOn', cb)
};
});
self.embark.registerConsoleCommand((cmd, _options) => {
return {
match: () => cmd === 'log swarm off',
process: (cb) => self.events.request('logs:swarm:turnOff', cb)
};
});
}
isSwarmEnabledInTheConfig() {
let {enabled, available_providers, dappConnection} = this.storageConfig;
return enabled && (available_providers.indexOf('swarm') > 0 || dappConnection.find(c => c.provider === 'swarm'));