|
|
@ -10,7 +10,7 @@ function MockLogger() {
|
|
|
|
|
|
|
|
|
|
|
|
var that = this;
|
|
|
|
var that = this;
|
|
|
|
this.messages = [];
|
|
|
|
this.messages = [];
|
|
|
|
|
|
|
|
|
|
|
|
this.log = function(level, message, exception) {
|
|
|
|
this.log = function(level, message, exception) {
|
|
|
|
that.messages.push({ level: level, message: message });
|
|
|
|
that.messages.push({ level: level, message: message });
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -18,7 +18,7 @@ function MockLogger() {
|
|
|
|
this.isLevelEnabled = function(level) {
|
|
|
|
this.isLevelEnabled = function(level) {
|
|
|
|
return level.isGreaterThanOrEqualTo(that.level);
|
|
|
|
return level.isGreaterThanOrEqualTo(that.level);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.level = levels.TRACE;
|
|
|
|
this.level = levels.TRACE;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -40,7 +40,7 @@ function MockRequest(remoteAddr, method, originalUrl, headers) {
|
|
|
|
|
|
|
|
|
|
|
|
function MockResponse() {
|
|
|
|
function MockResponse() {
|
|
|
|
var r = this;
|
|
|
|
var r = this;
|
|
|
|
this.end = function(chunk, encoding) {
|
|
|
|
this.end = function(chunk, encoding) {
|
|
|
|
r.emit('finish');
|
|
|
|
r.emit('finish');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -66,7 +66,7 @@ vows.describe('log4js connect logger').addBatch({
|
|
|
|
var clm = require('../lib/connect-logger');
|
|
|
|
var clm = require('../lib/connect-logger');
|
|
|
|
return clm;
|
|
|
|
return clm;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'should return a "connect logger" factory' : function(clm) {
|
|
|
|
'should return a "connect logger" factory' : function(clm) {
|
|
|
|
assert.isObject(clm);
|
|
|
|
assert.isObject(clm);
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -77,12 +77,12 @@ vows.describe('log4js connect logger').addBatch({
|
|
|
|
var cl = clm.connectLogger(ml);
|
|
|
|
var cl = clm.connectLogger(ml);
|
|
|
|
return cl;
|
|
|
|
return cl;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'should return a "connect logger"': function(cl) {
|
|
|
|
'should return a "connect logger"': function(cl) {
|
|
|
|
assert.isFunction(cl);
|
|
|
|
assert.isFunction(cl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'log events' : {
|
|
|
|
'log events' : {
|
|
|
|
topic: function(clm) {
|
|
|
|
topic: function(clm) {
|
|
|
|
var ml = new MockLogger();
|
|
|
|
var ml = new MockLogger();
|
|
|
@ -113,7 +113,7 @@ vows.describe('log4js connect logger').addBatch({
|
|
|
|
request(cl, 'GET', 'http://url', 200);
|
|
|
|
request(cl, 'GET', 'http://url', 200);
|
|
|
|
return ml.messages;
|
|
|
|
return ml.messages;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'check message': function(messages) {
|
|
|
|
'check message': function(messages) {
|
|
|
|
assert.isArray(messages);
|
|
|
|
assert.isArray(messages);
|
|
|
|
assert.isEmpty(messages);
|
|
|
|
assert.isEmpty(messages);
|
|
|
@ -130,7 +130,7 @@ vows.describe('log4js connect logger').addBatch({
|
|
|
|
setTimeout(function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
cb(null, ml.messages);
|
|
|
|
cb(null, ml.messages);
|
|
|
|
},10); },
|
|
|
|
},10); },
|
|
|
|
|
|
|
|
|
|
|
|
'check message': function(messages) {
|
|
|
|
'check message': function(messages) {
|
|
|
|
assert.isArray(messages);
|
|
|
|
assert.isArray(messages);
|
|
|
|
assert.equal(messages.length, 1);
|
|
|
|
assert.equal(messages.length, 1);
|
|
|
@ -168,7 +168,7 @@ vows.describe('log4js connect logger').addBatch({
|
|
|
|
request(cl, 'GET', 'http://meh', 500);
|
|
|
|
request(cl, 'GET', 'http://meh', 500);
|
|
|
|
setTimeout(function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
cb(null, ml.messages);
|
|
|
|
cb(null, ml.messages);
|
|
|
|
},10);
|
|
|
|
},10);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'should use INFO for 2xx': function(messages) {
|
|
|
|
'should use INFO for 2xx': function(messages) {
|
|
|
@ -198,7 +198,7 @@ vows.describe('log4js connect logger').addBatch({
|
|
|
|
request(cl, 'GET', 'http://blah', 200);
|
|
|
|
request(cl, 'GET', 'http://blah', 200);
|
|
|
|
setTimeout(function() {
|
|
|
|
setTimeout(function() {
|
|
|
|
cb(null, ml.messages);
|
|
|
|
cb(null, ml.messages);
|
|
|
|
},10);
|
|
|
|
},10);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
'should call the format function': function(messages) {
|
|
|
|
'should call the format function': function(messages) {
|
|
|
@ -213,8 +213,8 @@ vows.describe('log4js connect logger').addBatch({
|
|
|
|
ml.level = levels.INFO;
|
|
|
|
ml.level = levels.INFO;
|
|
|
|
var cl = clm.connectLogger(ml, ':req[Content-Type]');
|
|
|
|
var cl = clm.connectLogger(ml, ':req[Content-Type]');
|
|
|
|
request(
|
|
|
|
request(
|
|
|
|
cl,
|
|
|
|
cl,
|
|
|
|
'GET', 'http://blah', 200,
|
|
|
|
'GET', 'http://blah', 200,
|
|
|
|
{ 'Content-Type': 'application/json' }
|
|
|
|
{ 'Content-Type': 'application/json' }
|
|
|
|
);
|
|
|
|
);
|
|
|
|
setTimeout(function() {
|
|
|
|
setTimeout(function() {
|
|
|
@ -246,7 +246,7 @@ vows.describe('log4js connect logger').addBatch({
|
|
|
|
'should output the response header': function(messages) {
|
|
|
|
'should output the response header': function(messages) {
|
|
|
|
assert.equal(messages[0].message, 'application/cheese');
|
|
|
|
assert.equal(messages[0].message, 'application/cheese');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).export(module);
|
|
|
|
}).export(module);
|
|
|
|