debugging output.

This commit is contained in:
Christopher Jeffrey 2016-02-23 05:26:49 -08:00
parent 5773130b67
commit 1e1e214900
2 changed files with 26 additions and 7 deletions

View File

@ -45,6 +45,11 @@ if (bcoin.fs) {
}
}
if (bcoin.fs) {
bcoin._debug = bcoin.fs.createWriteStream(
bcoin.dir + '/debug.log', { flags: 'w' });
}
bcoin.ecdsa = bcoin.elliptic.ec('secp256k1');
assert(!bcoin.ecdsa.signature);
bcoin.ecdsa.signature = require('elliptic/lib/elliptic/ec/signature');

View File

@ -743,17 +743,31 @@ utils._inspect = function _inspect(obj, color) {
: obj;
};
utils.print = function print(msg) {
return typeof msg === 'object'
? process.stdout.write(utils._inspect(msg, !!process.stdout.isTTY) + '\n')
: console.log.apply(console, arguments);
utils.format = function format(args, color) {
color = color ? process.stdout.isTTY : false;
return typeof args[0] === 'object'
? utils._inspect(args[0], color) + '\n'
: util.format.apply(util, args) + '\n';
};
utils.print = function print() {
var args = Array.prototype.slice.call(arguments);
return process.stdout.write(utils.format(args, true));
};
utils.debug = function debug() {
if (!bcoin.debug)
return;
var args = Array.prototype.slice.call(arguments);
var msg;
return utils.print.apply(null, arguments);
if (bcoin.debug) {
msg = utils.format(args, true);
process.stdout.write(msg);
}
if (bcoin._debug) {
msg = utils.format(args, false);
bcoin._debug.write(msg);
}
};
utils.merge = function merge(target) {