From 0b7ed64082542638ab1d7d01decb5c3bf46275a0 Mon Sep 17 00:00:00 2001 From: Arnout Kazemier Date: Mon, 10 Oct 2011 21:32:54 +0200 Subject: [PATCH] Fixed logging options, closes #540 --- lib/logger.js | 3 ++- lib/manager.js | 6 ++++-- test/manager.test.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/lib/logger.js b/lib/logger.js index ce480eaadd..49d02c98df 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -60,6 +60,7 @@ var Logger = module.exports = function (opts) { opts = opts || {} this.colors = false !== opts.colors; this.level = 3; + this.enabled = true; }; /** @@ -71,7 +72,7 @@ var Logger = module.exports = function (opts) { Logger.prototype.log = function (type) { var index = levels.indexOf(type); - if (index > this.level) + if (index > this.level || !this.enabled) return this; console.log.apply( diff --git a/lib/manager.js b/lib/manager.js index 2b0b755df2..8abd95ac1c 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -68,6 +68,7 @@ function Manager (server, options) { , transports: defaultTransports , authorization: false , 'log level': 3 + , 'log colors': true , 'close timeout': 25 , 'heartbeat timeout': 15 , 'heartbeat interval': 20 @@ -147,10 +148,11 @@ Manager.prototype.__defineGetter__('store', function () { */ Manager.prototype.__defineGetter__('log', function () { - if (this.disabled('log')) return; - var logger = this.get('logger'); + logger.level = this.get('log level') || -1; + logger.colors = this.get('log colors'); + logger.enabled = this.enabled('log'); return logger; }); diff --git a/test/manager.test.js b/test/manager.test.js index bd0d2838ae..508a7e0d2c 100644 --- a/test/manager.test.js +++ b/test/manager.test.js @@ -515,6 +515,49 @@ module.exports = { io.get('resource').should.equal('/my resource'); io.get('custom').should.equal('opt'); + io.server.close(); + done(); + }, + + 'test disabling the log': function (done) { + var port = ++ports + , io = sio.listen(port, { log: false }) + , _console = console.log + , calls = 0; + + // the logger uses console.log to output data, override it to see if get's + // used + console.log = function () { ++calls }; + + io.log.debug('test'); + io.log.log('testing'); + + console.log = _console; + calls.should.equal(0); + + io.server.close(); + done(); + }, + + 'test disabling logging with colors': function (done) { + var port = ++ports + , io = sio.listen(port, { 'log colors': false }) + , _console = console.log + , calls = 0; + + // the logger uses console.log to output data, override it to see if get's + // used + console.log = function (data) { + ++calls; + data.indexOf('\033').should.equal(-1); + }; + + io.log.debug('test'); + io.log.log('testing'); + + console.log = _console; + calls.should.equal(2); + io.server.close(); done(); }