logger: better context handling.

This commit is contained in:
Christopher Jeffrey 2017-03-12 10:41:27 -07:00
parent 896ffdd3f5
commit f7853aa639
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
4 changed files with 12 additions and 4 deletions

View File

@ -56,7 +56,7 @@ function RPC(node) {
this.pool = node.pool;
this.fees = node.fees;
this.miner = node.miner;
this.logger = node.logger;
this.logger = node.logger.context('rpc');
this.mining = false;
this.procLimit = 0;

View File

@ -29,6 +29,7 @@ function Logger(options) {
this.console = true;
this.filename = null;
this.stream = null;
this.contexts = {};
this.init(options);
}
@ -378,7 +379,14 @@ Logger.prototype.log = function log(level, module, args) {
*/
Logger.prototype.context = function context(module) {
return new LoggerContext(this, module);
var context = this.contexts[module];
if (!context) {
context = new LoggerContext(this, module);
this.contexts[module] = context;
}
return context;
};
/**

View File

@ -39,7 +39,7 @@ function HTTPServer(options) {
this.options = options;
this.network = this.options.network;
this.logger = this.options.logger;
this.logger = this.options.logger.context('http');
this.walletdb = this.options.walletdb;
this.server = new HTTPBase(this.options);

View File

@ -45,7 +45,7 @@ function RPC(wdb) {
this.wdb = wdb;
this.network = wdb.network;
this.logger = wdb.logger;
this.logger = wdb.logger.context('rpc');
this.client = wdb.client;
this.wallet = null;