diff --git a/index.js b/index.js index faf4769..c935541 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,9 @@ const Client = require('./lib/client'); +const debug = require("debug"); +const debugLog = debug("electrumClient"); + class ElectrumClient extends Client { constructor(port, host, protocol, options) { super(port, host, protocol, options); @@ -63,7 +66,7 @@ class ElectrumClient extends Client { this.timeout = setTimeout(() => { if (this.timeLastCall !== 0 && new Date().getTime() > this.timeLastCall + 5000) { this.server_ping().catch((reason) => { - console.log('keepalive ping failed because of', reason); + debugLog('keepalive ping failed because of', reason); }); } }, 5000); @@ -78,7 +81,7 @@ class ElectrumClient extends Client { } reconnect() { - console.log('electrum reconnect'); + debugLog("Electrum reconnect"); this.initSocket(); return this.initElectrum(this.electrumConfig); } diff --git a/lib/TlsSocketWrapper.js b/lib/TlsSocketWrapper.js index ca29048..e7cac9a 100644 --- a/lib/TlsSocketWrapper.js +++ b/lib/TlsSocketWrapper.js @@ -1,3 +1,6 @@ +const debug = require("debug"); +const debugLog = debug("electrumClient"); + /** * Simple wrapper to mimick Socket class from NET package, since TLS package has slightly different API. * We implement several methods that TCP sockets are expected to have. We will proxy call them as soon as @@ -69,7 +72,7 @@ class TlsSocketWrapper { connect(port, host, callback) { // resulting TLSSocket extends this._socket = this._tls.connect({ port: port, host: host, rejectUnauthorized: false }, () => { - console.log('TLS Connected to ', host, port); + debugLog('TLS Connected to ', host, port); return callback(); }); diff --git a/lib/client.js b/lib/client.js index 6fdf6b5..6205549 100644 --- a/lib/client.js +++ b/lib/client.js @@ -17,6 +17,9 @@ const TlsSocketWrapper = require('./TlsSocketWrapper.js'); const EventEmitter = require('events').EventEmitter; const util = require('./util'); +const debug = require("debug"); +const debugLog = debug("electrumClient"); + class Client { constructor(port, host, protocol, options) { this.id = 0; @@ -156,7 +159,7 @@ class Client { callback(null, msg.result || msg); } } else { - console.log("Can't get callback"); + debugLog("Can't get callback"); } } @@ -188,7 +191,7 @@ class Client { } onError(e) { - console.log('OnError:' + e); + debugLog('OnError:' + e); } } diff --git a/package.json b/package.json index 6ff5692..805aa03 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "dependencies": {}, + "dependencies": { + "debug": "~4.1.1", + }, "devDependencies": {}, "repository": { "type": "git",