diff --git a/lib/http/rpc.js b/lib/http/rpc.js index 9b1bd7e6..6b7a4675 100644 --- a/lib/http/rpc.js +++ b/lib/http/rpc.js @@ -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; diff --git a/lib/node/logger.js b/lib/node/logger.js index 1c55dd21..4bf1a8ad 100644 --- a/lib/node/logger.js +++ b/lib/node/logger.js @@ -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; }; /** diff --git a/lib/wallet/http.js b/lib/wallet/http.js index 51107274..8aeeea74 100644 --- a/lib/wallet/http.js +++ b/lib/wallet/http.js @@ -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); diff --git a/lib/wallet/rpc.js b/lib/wallet/rpc.js index cf5b5dc3..6246b752 100644 --- a/lib/wallet/rpc.js +++ b/lib/wallet/rpc.js @@ -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;