diff --git a/lib/modules/blockchain_process/blockchainProcessLauncher.js b/lib/modules/blockchain_process/blockchainProcessLauncher.js index 992fbeae5..992d99034 100644 --- a/lib/modules/blockchain_process/blockchainProcessLauncher.js +++ b/lib/modules/blockchain_process/blockchainProcessLauncher.js @@ -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'); }); diff --git a/lib/modules/blockchain_process/index.js b/lib/modules/blockchain_process/index.js index 66fafe469..3d04214bb 100644 --- a/lib/modules/blockchain_process/index.js +++ b/lib/modules/blockchain_process/index.js @@ -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; diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index 45b05d477..c8f697f3d 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -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')); diff --git a/lib/modules/storage/storageProcessesLauncher.js b/lib/modules/storage/storageProcessesLauncher.js index 7b2cd596a..b41ea74f4 100644 --- a/lib/modules/storage/storageProcessesLauncher.js +++ b/lib/modules/storage/storageProcessesLauncher.js @@ -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; + }); + }); } } diff --git a/lib/modules/swarm/index.js b/lib/modules/swarm/index.js index fb11881b5..bbd975c09 100644 --- a/lib/modules/swarm/index.js +++ b/lib/modules/swarm/index.js @@ -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'));