debug file flag.

This commit is contained in:
Christopher Jeffrey 2016-02-23 21:29:26 -08:00
parent ad173d0f22
commit 26969d823a
2 changed files with 8 additions and 12 deletions

View File

@ -11,11 +11,8 @@ bcoin.isBrowser =
(typeof process !== 'undefined' && process.browser)
|| typeof window !== 'undefined';
if (process.env.BCOIN_DEBUG) {
bcoin.debug = process.env.BCOIN_DEBUG;
if (bcoin.debug === '0' || bcoin.debug === '1')
bcoin.debug = +bcoin.debug === 1;
}
bcoin.debug = +process.env.BCOIN_DEBUG === 1;
bcoin.debugFile = +process.env.BCOIN_DEBUGFILE !== 0;
bcoin.bn = require('bn.js');
bcoin.elliptic = require('elliptic');
@ -45,11 +42,6 @@ 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

@ -764,9 +764,13 @@ utils.debug = function debug() {
process.stdout.write(msg);
}
if (bcoin._debug) {
if (bcoin.debugFile && bcoin.fs) {
if (!bcoin._debug) {
bcoin._debug = bcoin.fs.createWriteStream(
bcoin.dir + '/debug.log', { flags: 'a' });
}
msg = utils.format(args, false);
bcoin._debug.write(msg);
bcoin._debug.write(process.pid + ': ' + msg);
}
};