diff --git a/src/js/remote.js b/src/js/remote.js index 5968f17bc0..302ca4bcd4 100644 --- a/src/js/remote.js +++ b/src/js/remote.js @@ -22,6 +22,8 @@ var Amount = require('./amount.js').Amount; var Currency = require('./amount.js').Currency; var UInt160 = require('./amount.js').UInt160; +var utils = require('./utils'); + // Request events emitted: // 'success' : Request successful. // 'error' : Request failed. @@ -461,12 +463,12 @@ Remote.prototype._connect_message = function (ws, json) { unexpected = true; } else if ('success' === message.status) { - if (this.trace) console.log("remote: response: %s", JSON.stringify(message, undefined, 2)); + if (this.trace) utils.logObject("remote: response: %s", message); request.emit('success', message.result); } else if (message.error) { - if (this.trace) console.log("remote: error: %s", JSON.stringify(message, undefined, 2)); + if (this.trace) utils.logObject("remote: error: %s", message); request.emit('error', { 'error' : 'remoteError', @@ -492,7 +494,7 @@ Remote.prototype._connect_message = function (ws, json) { // Account subscription event case 'account': - if (this.trace) console.log("remote: account: %s", JSON.stringify(message, undefined, 2)); + if (this.trace) utils.logObject("remote: account: %s", message); break; default: @@ -536,12 +538,12 @@ Remote.prototype.request = function (request) { this.id += 1; // Advance id. - if (this.trace) console.log("remote: request: %s", JSON.stringify(request.message)); + if (this.trace) utils.logObject("remote: request: %s", request.message); this.ws.send(JSON.stringify(request.message)); } else { - if (this.trace) console.log("remote: request: DROPPING: %s", JSON.stringify(request.message)); + if (this.trace) utils.logObject("remote: request: DROPPING: %s", request.message); } }; diff --git a/src/js/utils.js b/src/js/utils.js index 34131e9408..563969fee4 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -70,10 +70,16 @@ var stringToArray = function (s) { return a; }; -exports.trace = trace; -exports.arraySet = arraySet; -exports.hexToString = hexToString; +var logObject = function (msg, obj) { + console.log(msg, JSON.stringify(obj, undefined, 2)); +}; + + +exports.trace = trace; +exports.arraySet = arraySet; +exports.hexToString = hexToString; exports.stringToArray = stringToArray; -exports.stringToHex = stringToHex; +exports.stringToHex = stringToHex; +exports.logObject = logObject; // vim:sw=2:sts=2:ts=8:et diff --git a/src/js/utils.web.js b/src/js/utils.web.js new file mode 100644 index 0000000000..b98916e178 --- /dev/null +++ b/src/js/utils.web.js @@ -0,0 +1,7 @@ +exports = module.exports = require('./utils.js'); + +// We override this function for browsers, because they print objects nicer +// natively than JSON.stringify can. +exports.logObject = function (msg, obj) { + console.log(msg, "", obj); +};