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 c0bb7cd0e6..49aaf4da08 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -69,6 +69,7 @@ function Manager (server, options) { , authorization: false , blacklist: ['disconnect'] , 'log level': 3 + , 'log colors': true , 'close timeout': 25 , 'heartbeat timeout': 15 , 'heartbeat interval': 20 @@ -148,10 +149,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(); } diff --git a/test/static.test.js b/test/static.test.js index 6feed80b58..9333d0cb15 100644 --- a/test/static.test.js +++ b/test/static.test.js @@ -519,5 +519,27 @@ module.exports = { io.server.close(); done(); }); - } + }, + + 'test that etags are ignored for versioned requests': function (done) { + var port = ++ports + , io = sio.listen(port) + , cl = client(port); + + io.enable('browser client etag'); + + cl.get('/socket.io/socket.io.v0.8.9.js', function (res, data) { + should.strictEqual(res.headers.etag, undefined); + res.headers['content-type'].should.eql('application/javascript'); + res.headers['content-length'].should.match(/([0-9]+)/); + res.headers['cache-control'] + .indexOf(io.get('browser client expires')).should.be.above(-1); + + data.should.match(/XMLHttpRequest/); + + cl.end(); + io.server.close(); + done(); + }); + }, };