Skip to content

Commit

Permalink
Merge pull request socketio#563 from 3rd-Eden/logger
Browse files Browse the repository at this point in the history
Logger
  • Loading branch information
rauchg committed Oct 11, 2011
2 parents 0224e4a + 0b7ed64 commit 175fe85
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var Logger = module.exports = function (opts) {
opts = opts || {}
this.colors = false !== opts.colors;
this.level = 3;
this.enabled = true;
};

/**
Expand All @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
});
Expand Down
43 changes: 43 additions & 0 deletions test/manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
24 changes: 23 additions & 1 deletion test/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
},
};

0 comments on commit 175fe85

Please sign in to comment.