Skip to content
This repository was archived by the owner on Feb 11, 2020. It is now read-only.

Commit 8d134ab

Browse files
committed
Refactored and improved logger setup.
1 parent 09def4f commit 8d134ab

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/client.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var rewriteTopic = function(topic) {
1717
function Client(conn, server) {
1818
this.connection = conn;
1919
this.server = server;
20-
this.logger = server.logger;
20+
this.logger = server.logger.child({ client: this }, true);
2121
this.subscriptions = {};
2222

2323
this.nextId = 0;
@@ -226,7 +226,6 @@ Client.prototype.handleConnect = function(packet) {
226226
var that = this, logger = this.logger, client = this.connection;
227227

228228
this.id = packet.clientId;
229-
logger = that.logger.child({ client: this });
230229

231230
if (this.id.length > 23) {
232231
client.connack({

lib/server.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var defaults = {
3838
* - `baseRetryTimeout`, the retry timeout for the exponential
3939
* backoff algorithm (default is 1s).
4040
* - `logger`, the options for Bunyan.
41+
* - `logger.childOf`, the parent Bunyan logger.
4142
* - `persitance`, the options for the persistence.
4243
* A sub-key `factory` is used to specify what persitance
4344
* to use.
@@ -75,7 +76,15 @@ function Server(opts, callback) {
7576
callback = callback || function() {};
7677

7778
this.clients = {};
78-
this.logger = bunyan.createLogger(this.opts.logger);
79+
80+
if (this.opts.logger.childOf) {
81+
this.logger = this.opts.logger.childOf;
82+
delete this.opts.logger.childOf;
83+
delete this.opts.logger.name;
84+
this.logger = this.logger.child(this.opts.logger);
85+
} else {
86+
this.logger = bunyan.createLogger(this.opts.logger);
87+
}
7988

8089
var that = this;
8190

test/common.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ global.moscaSettings = function() {
3838
return {
3939
port: nextPort(),
4040
logger: {
41-
name: "moscaTests",
41+
childOf: globalLogger,
4242
level: 60
4343
}
4444
};

0 commit comments

Comments
 (0)