diff --git a/lib/bcoin.js b/lib/bcoin.js index 767a256a..6aa91fee 100644 --- a/lib/bcoin.js +++ b/lib/bcoin.js @@ -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'); diff --git a/lib/bcoin/utils.js b/lib/bcoin/utils.js index 89cfe454..3631423c 100644 --- a/lib/bcoin/utils.js +++ b/lib/bcoin/utils.js @@ -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); } };