From 22ed138aa2c301dcc89b20619c694e2ef70fb754 Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Thu, 15 Nov 2018 10:06:36 +0100 Subject: [PATCH 1/9] First attempt at activating silent option in cli --- src/cli/utils.js | 1 + src/core/components/libp2p.js | 2 +- src/core/index.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cli/utils.js b/src/cli/utils.js index 9c462bc3d7..64e2eee39f 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -47,6 +47,7 @@ exports.getIPFS = (argv, callback) => { // Required inline to reduce startup time const IPFS = require('../core') const node = new IPFS({ + print: argv.print, repo: exports.getRepoPath(), init: false, start: false, diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index d195623467..2f2405e5af 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -107,7 +107,7 @@ module.exports = function libp2p (self) { if (err) { return callback(err) } self._libp2pNode.peerInfo.multiaddrs.forEach((ma) => { - console.log('Swarm listening on', ma.toString()) + self._print('Swarm listening on ', console.log(ma.toString())) }) callback() diff --git a/src/core/index.js b/src/core/index.js index 8425cab7a2..8aa1fd823c 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -127,6 +127,7 @@ class IPFS extends EventEmitter { this._preload = preload(this) this._mfsPreload = mfsPreload(this) this._ipns = undefined + this._print = this._options.silent ? this.log : console.log // IPFS Core exposed components // - for booting up a node From ec4b3e362042d15ba319c81765ebeb663738dc23 Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Wed, 21 Nov 2018 16:30:02 +0100 Subject: [PATCH 2/9] Updated Changes --- src/cli/utils.js | 3 ++- src/core/components/libp2p.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cli/utils.js b/src/cli/utils.js index 64e2eee39f..14d95225cf 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -44,10 +44,11 @@ exports.getIPFS = (argv, callback) => { return callback(null, getAPICtl(argv.api), promisify((cb) => cb())) } + debugger // Required inline to reduce startup time const IPFS = require('../core') const node = new IPFS({ - print: argv.print, + silent: argv.silent, repo: exports.getRepoPath(), init: false, start: false, diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index 2f2405e5af..c5e3a40b1c 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -107,7 +107,7 @@ module.exports = function libp2p (self) { if (err) { return callback(err) } self._libp2pNode.peerInfo.multiaddrs.forEach((ma) => { - self._print('Swarm listening on ', console.log(ma.toString())) + self._print('Swarm listening on', ma.toString()) }) callback() From f3b9aae2ad72724bf3c5188255ce757b047f3276 Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Thu, 22 Nov 2018 13:36:54 +0100 Subject: [PATCH 3/9] Swarm output is silenced --- src/cli/bin.js | 7 ++++++- src/cli/utils.js | 1 - src/http/index.js | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cli/bin.js b/src/cli/bin.js index 401357ebf3..7878a05978 100755 --- a/src/cli/bin.js +++ b/src/cli/bin.js @@ -24,7 +24,12 @@ const cli = yargs desc: 'Write no output', type: 'boolean', default: false, - coerce: ('silent', silent => silent ? utils.disablePrinting() : silent) + coerce: ('silent', silent => { + if (silent) { + utils.disablePrinting() + } + return silent + }) }) .option('pass', { desc: 'Pass phrase for the keys', diff --git a/src/cli/utils.js b/src/cli/utils.js index 14d95225cf..46777125e5 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -44,7 +44,6 @@ exports.getIPFS = (argv, callback) => { return callback(null, getAPICtl(argv.api), promisify((cb) => cb())) } - debugger // Required inline to reduce startup time const IPFS = require('../core') const node = new IPFS({ diff --git a/src/http/index.js b/src/http/index.js index dd6b19b430..515e83181e 100644 --- a/src/http/index.js +++ b/src/http/index.js @@ -68,6 +68,7 @@ function HttpApi (repo, config, cliArgs) { try { // start the daemon this.node = new IPFS({ + silent: cliArgs.silent, repo: repo, init: init, start: true, From 51f19993c189d386a9bedd52fdae79eae9121991 Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Tue, 27 Nov 2018 14:53:22 +0100 Subject: [PATCH 4/9] All messages are silinced --- src/http/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/http/index.js b/src/http/index.js index 515e83181e..fbace44d3b 100644 --- a/src/http/index.js +++ b/src/http/index.js @@ -158,9 +158,9 @@ function HttpApi (repo, config, cliArgs) { api.info.ma = uriToMultiaddr(api.info.uri) gateway.info.ma = uriToMultiaddr(gateway.info.uri) - console.log('API listening on %s', api.info.ma) - console.log('Gateway (read only) listening on %s', gateway.info.ma) - console.log('Web UI available at %s', api.info.uri + '/webui') + this.node._print('API listening on %s', api.info.ma) + this.node._print('Gateway (read only) listening on %s', gateway.info.ma) + this.node._print('Web UI available at %s', api.info.uri + '/webui') // for the CLI to know the where abouts of the API this.node._repo.apiAddr.set(api.info.ma, cb) From 75d6b01f628268fce879659fd69788c6505903eb Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Mon, 3 Dec 2018 11:44:34 +0100 Subject: [PATCH 5/9] fix: tests for silent option --- test/core/create-node.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/core/create-node.spec.js b/test/core/create-node.spec.js index f1e8c5cc75..0ffdac5d41 100644 --- a/test/core/create-node.spec.js +++ b/test/core/create-node.spec.js @@ -7,6 +7,7 @@ const dirtyChai = require('dirty-chai') const expect = chai.expect chai.use(dirtyChai) const series = require('async/series') +const sinon = require('sinon') const waterfall = require('async/waterfall') const parallel = require('async/parallel') const os = require('os') @@ -131,6 +132,21 @@ describe('create node', function () { }) }) + it('should be silent', (done) => { + sinon.spy(console, 'log') + + const ipfs = new IPFS({ + silent: true, + repo: tempRepo + }) + + ipfs.on('ready', () => { + expect(console.log.called).to.be.false() + console.log.restore() + done() + }) + }) + it('init: false errors (start default: true) and errors only once', function (done) { this.timeout(80 * 1000) From 563baf326ba516d25b4e91000dd04adc27b52ed8 Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Mon, 3 Dec 2018 15:48:27 +0100 Subject: [PATCH 6/9] fix: added test for silent argument in cli api --- test/cli/daemon.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/cli/daemon.js b/test/cli/daemon.js index d60d591279..a9aaccacf0 100644 --- a/test/cli/daemon.js +++ b/test/cli/daemon.js @@ -126,6 +126,21 @@ describe('daemon', () => { }) }) + it('should be silent', function (done) { + this.timeout(10 * 1000) + const res = ipfs('daemon --silent') + res.catch(function () {}) // Handles the unhandled promise rejection + let output = '' + const onData = (d) => { output += d } + res.stdout.on('data', onData) + res.stderr.on('data', onData) + setTimeout(function () { + res.kill() + expect(output).to.be.empty() + done() + }, 5 * 1000) + }) + it('should present ipfs path help when option help is received', function (done) { this.timeout(100 * 1000) From 84b37edff9ff151409dd308809f720dce7c1202b Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Mon, 3 Dec 2018 16:12:20 +0100 Subject: [PATCH 7/9] fix: added docs --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 2485714de0..45b553ae73 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,14 @@ Instead of a boolean, you may provide an object with custom initialization optio A passphrase to encrypt/decrypt your keys. +##### `options.silent` + +| Type | Default | +|------|---------| +| string | `null` | + +The silent option prevents swarm info output in the cli and http client. + ##### `options.relay` | Type | Default | From f9784967cf4295573dc88a869a755e0d46f5e123 Mon Sep 17 00:00:00 2001 From: Portia Burton Date: Tue, 4 Dec 2018 11:29:11 +0100 Subject: [PATCH 8/9] fix: small edits to documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 45b553ae73..67c7ecaa25 100644 --- a/README.md +++ b/README.md @@ -272,9 +272,9 @@ A passphrase to encrypt/decrypt your keys. | Type | Default | |------|---------| -| string | `null` | +| Boolean | `false` | -The silent option prevents swarm info output in the cli and http client. +Prevents all logging output from the IPFS node. ##### `options.relay` From d075bdc2337272e00ec00f51f869daf1deaaa317 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 7 Dec 2018 16:32:21 +0000 Subject: [PATCH 9/9] fix: libp2p tests License: MIT Signed-off-by: Alan Shaw --- test/core/libp2p.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/core/libp2p.spec.js b/test/core/libp2p.spec.js index aacc4215a3..c7acca3a6d 100644 --- a/test/core/libp2p.spec.js +++ b/test/core/libp2p.spec.js @@ -76,6 +76,7 @@ describe('libp2p customization', function () { }, _peerInfo: peerInfo, _peerBook: peerBook, + _print: console.log, config: mockConfig, _options: { libp2p: (opts) => { @@ -122,6 +123,7 @@ describe('libp2p customization', function () { }, _peerInfo: peerInfo, _peerBook: peerBook, + _print: console.log, config: mockConfig } @@ -164,6 +166,7 @@ describe('libp2p customization', function () { }, _peerInfo: peerInfo, _peerBook: peerBook, + _print: console.log, config: mockConfig, _options: { config: {