node: refactor config options.

This commit is contained in:
Christopher Jeffrey 2017-03-14 05:16:52 -07:00
parent b7c847059a
commit 4674109706
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
6 changed files with 42 additions and 24 deletions

View File

@ -13,6 +13,7 @@ node = new bcoin.fullnode({
argv: true,
env: true,
logFile: true,
logConsole: true,
logLevel: 'debug',
db: 'leveldb',
listen: true,

View File

@ -15,6 +15,7 @@ node = bcoin.spvnode({
argv: true,
env: true,
logFile: true,
logConsole: true,
logLevel: 'debug',
db: 'leveldb',
listen: true,

View File

@ -9,7 +9,11 @@ var server = require('../lib/wallet/server');
var wdb = server.create({
config: true,
argv: true,
env: true
env: true,
logFile: true,
logConsole: true,
logLevel: 'debug',
db: 'leveldb'
});
wdb.on('error', function(err) {

View File

@ -36,7 +36,8 @@ function Logger(options) {
this.contexts = {};
this.locker = new Lock();
this.init(options);
if (options)
this.set(options);
}
/**
@ -131,14 +132,13 @@ Logger.colors = [
];
/**
* Initialize the logger.
* @private
* Set logger options.
* @param {Object} options
*/
Logger.prototype.init = function init(options) {
if (!options)
return;
Logger.prototype.set = function set(options) {
assert(options);
assert(this.closed);
if (typeof options === 'string') {
this.setLevel(options);
@ -196,11 +196,15 @@ Logger.prototype._open = co(function* open() {
if (fs.unsupported)
return;
if (!this.filename)
if (!this.filename) {
this.closed = false;
return;
}
if (this.stream)
if (this.stream) {
this.closed = false;
return;
}
if (this.shrink)
yield this.truncate();

View File

@ -48,7 +48,7 @@ function Node(options) {
this.stack = [];
this.spv = false;
this.logger = new Logger();
this.logger = null;
this.chain = null;
this.fees = null;
this.mempool = null;
@ -68,24 +68,22 @@ util.inherits(Node, AsyncObject);
*/
Node.prototype.initOptions = function initOptions() {
var logger = new Logger();
var config = this.config;
if (config.has('logger'))
this.logger = config.obj('logger');
logger = config.obj('logger');
if (config.bool('log-file'))
this.logger.setFile(config.location('debug.log'));
logger.set({
filename: config.bool('log-file')
? config.location('debug.log')
: null,
level: config.str('log-level'),
console: config.bool('log-console'),
shrink: config.bool('log-shrink')
});
if (config.has('log-level'))
this.logger.setLevel(config.str('log-level'));
if (config.has('log-console'))
this.logger.console = config.bool('log-console');
if (config.bool('debug'))
this.logger.shrink = false;
this.logger = this.logger.context('node');
this.logger = logger.context('node');
};
/**

View File

@ -34,13 +34,23 @@ server.create = function create(options) {
if (options.config)
config.open('wallet.conf');
if (config.has('logger'))
logger = config.obj('logger');
client = new Client({
network: config.network,
uri: config.str('node-uri'),
apiKey: config.str('node-api-key')
});
logger.setFile(config.location('wallet.log'));
logger.set({
filename: config.bool('log-file')
? config.location('wallet.log')
: null,
level: config.str('log-level'),
console: config.bool('log-console'),
shrink: config.bool('log-shrink')
});
return new WalletDB({
network: config.network,