fixed the nolog tests
This commit is contained in:
parent
613a077a61
commit
61078e88ef
@ -45,8 +45,8 @@ function getLogger(logger4js, options) {
|
|||||||
// mount safety
|
// mount safety
|
||||||
if (req._logging) return next();
|
if (req._logging) return next();
|
||||||
|
|
||||||
// nologs
|
// nologs
|
||||||
if(nolog && nolog.test(req.originalUrl)) return next();
|
if (nolog && nolog.test(req.originalUrl)) return next();
|
||||||
|
|
||||||
if (thislogger.isLevelEnabled(level)) {
|
if (thislogger.isLevelEnabled(level)) {
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ function getLogger(logger4js, options) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//ensure next gets always called
|
//ensure next gets always called
|
||||||
next();
|
next();
|
||||||
};
|
};
|
||||||
@ -165,4 +165,4 @@ function createNoLogCondition(nolog, type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.connectLogger = getLogger;
|
exports.connectLogger = getLogger;
|
||||||
|
@ -12,18 +12,17 @@ function Level(level, levelStr) {
|
|||||||
*/
|
*/
|
||||||
function toLevel(sArg, defaultLevel) {
|
function toLevel(sArg, defaultLevel) {
|
||||||
|
|
||||||
if (sArg === null) {
|
if (!sArg) {
|
||||||
return defaultLevel;
|
return defaultLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof sArg == "string") {
|
if (typeof sArg == "string") {
|
||||||
var s = sArg.toUpperCase();
|
var s = sArg.toUpperCase();
|
||||||
if (module.exports[s]) {
|
if (module.exports[s]) {
|
||||||
return module.exports[s];
|
return module.exports[s];
|
||||||
}
|
} else {
|
||||||
else {
|
return defaultLevel;
|
||||||
return defaultLevel;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return toLevel(sArg.toString());
|
return toLevel(sArg.toString());
|
||||||
|
@ -40,84 +40,84 @@ function MockResponse(statusCode) {
|
|||||||
|
|
||||||
vows.describe('log4js connect logger').addBatch({
|
vows.describe('log4js connect logger').addBatch({
|
||||||
'getConnectLoggerModule': {
|
'getConnectLoggerModule': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
var clm = require('../lib/connect-logger');
|
var clm = require('../lib/connect-logger');
|
||||||
return clm;
|
return clm;
|
||||||
},
|
|
||||||
|
|
||||||
'should return a "connect logger" factory' : function(clm) {
|
|
||||||
assert.isObject(clm);
|
|
||||||
},
|
|
||||||
|
|
||||||
'nolog String' : {
|
|
||||||
topic: function(clm) {
|
|
||||||
var ml = new MockLogger();
|
|
||||||
var cl = clm.connectLogger(ml, {nolog: "\\.gif"});
|
|
||||||
return {cl: cl, ml: ml};
|
|
||||||
},
|
},
|
||||||
|
|
||||||
'check unmatch url request': {
|
'should return a "connect logger" factory' : function(clm) {
|
||||||
topic: function(d){
|
assert.isObject(clm);
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
|
},
|
||||||
var res = new MockResponse(200);
|
|
||||||
d.cl(req, res, function() { });
|
'nolog String' : {
|
||||||
res.end('chunk', 'encoding');
|
topic: function(clm) {
|
||||||
return d.ml.messages;
|
var ml = new MockLogger();
|
||||||
}
|
var cl = clm.connectLogger(ml, { nolog: "\\.gif" });
|
||||||
, 'check message': function(messages){
|
return {cl: cl, ml: ml};
|
||||||
assert.isArray(messages);
|
},
|
||||||
assert.equal(messages.length, 1);
|
|
||||||
assert.equal(messages[0].level, levels.INFO);
|
'check unmatch url request': {
|
||||||
assert.include(messages[0].message, 'GET');
|
topic: function(d){
|
||||||
assert.include(messages[0].message, 'http://url');
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
|
||||||
assert.include(messages[0].message, 'my.remote.addr');
|
var res = new MockResponse(200);
|
||||||
assert.include(messages[0].message, '200');
|
d.cl(req, res, function() { });
|
||||||
messages.pop();
|
res.end('chunk', 'encoding');
|
||||||
|
return d.ml.messages;
|
||||||
|
}
|
||||||
|
, 'check message': function(messages){
|
||||||
|
assert.isArray(messages);
|
||||||
|
assert.equal(messages.length, 1);
|
||||||
|
assert.equal(messages[0].level, levels.INFO);
|
||||||
|
assert.include(messages[0].message, 'GET');
|
||||||
|
assert.include(messages[0].message, 'http://url');
|
||||||
|
assert.include(messages[0].message, 'my.remote.addr');
|
||||||
|
assert.include(messages[0].message, '200');
|
||||||
|
messages.pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'check match url request': {
|
'check match url request': {
|
||||||
topic: function(d) {
|
topic: function(d) {
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
|
||||||
var res = new MockResponse(200);
|
var res = new MockResponse(200);
|
||||||
d.cl(req, res, function() { });
|
d.cl(req, res, function() { });
|
||||||
res.end('chunk', 'encoding');
|
res.end('chunk', 'encoding');
|
||||||
return d.ml.messages;
|
return d.ml.messages;
|
||||||
}
|
}
|
||||||
, 'check message': function(messages) {
|
, 'check message': function(messages) {
|
||||||
assert.isArray(messages);
|
assert.isArray(messages);
|
||||||
assert.equal(messages.length, 0);
|
assert.equal(messages.length, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'nolog Strings' : {
|
|
||||||
topic: function(clm) {
|
|
||||||
var ml = new MockLogger();
|
|
||||||
var cl = clm.connectLogger(ml, {nolog: "\\.gif|\\.jpe?g"});
|
|
||||||
return {cl: cl, ml: ml};
|
|
||||||
},
|
|
||||||
|
|
||||||
'check unmatch url request (png)': {
|
'nolog Strings' : {
|
||||||
topic: function(d){
|
topic: function(clm) {
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
|
var ml = new MockLogger();
|
||||||
var res = new MockResponse(200);
|
var cl = clm.connectLogger(ml, {nolog: "\\.gif|\\.jpe?g"});
|
||||||
d.cl(req, res, function() { });
|
return {cl: cl, ml: ml};
|
||||||
res.end('chunk', 'encoding');
|
},
|
||||||
return d.ml.messages;
|
|
||||||
}
|
'check unmatch url request (png)': {
|
||||||
, 'check message': function(messages){
|
topic: function(d){
|
||||||
assert.isArray(messages);
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
|
||||||
assert.equal(messages.length, 1);
|
var res = new MockResponse(200);
|
||||||
assert.equal(messages[0].level, levels.INFO);
|
d.cl(req, res, function() { });
|
||||||
assert.include(messages[0].message, 'GET');
|
res.end('chunk', 'encoding');
|
||||||
assert.include(messages[0].message, 'http://url');
|
return d.ml.messages;
|
||||||
assert.include(messages[0].message, 'my.remote.addr');
|
}
|
||||||
assert.include(messages[0].message, '200');
|
, 'check message': function(messages){
|
||||||
messages.pop();
|
assert.isArray(messages);
|
||||||
|
assert.equal(messages.length, 1);
|
||||||
|
assert.equal(messages[0].level, levels.INFO);
|
||||||
|
assert.include(messages[0].message, 'GET');
|
||||||
|
assert.include(messages[0].message, 'http://url');
|
||||||
|
assert.include(messages[0].message, 'my.remote.addr');
|
||||||
|
assert.include(messages[0].message, '200');
|
||||||
|
messages.pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'check match url request (gif)': {
|
'check match url request (gif)': {
|
||||||
topic: function(d) {
|
topic: function(d) {
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
|
||||||
@ -171,7 +171,7 @@ vows.describe('log4js connect logger').addBatch({
|
|||||||
messages.pop();
|
messages.pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'check match url request (gif)': {
|
'check match url request (gif)': {
|
||||||
topic: function(d) {
|
topic: function(d) {
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
|
||||||
@ -185,7 +185,7 @@ vows.describe('log4js connect logger').addBatch({
|
|||||||
assert.equal(messages.length, 0);
|
assert.equal(messages.length, 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'check match url request (jpeg)': {
|
'check match url request (jpeg)': {
|
||||||
topic: function(d) {
|
topic: function(d) {
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif
|
||||||
@ -226,7 +226,7 @@ vows.describe('log4js connect logger').addBatch({
|
|||||||
messages.pop();
|
messages.pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'check match url request (gif)': {
|
'check match url request (gif)': {
|
||||||
topic: function(d) {
|
topic: function(d) {
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
|
||||||
@ -240,7 +240,7 @@ vows.describe('log4js connect logger').addBatch({
|
|||||||
assert.equal(messages.length, 0);
|
assert.equal(messages.length, 0);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'check match url request (jpeg)': {
|
'check match url request (jpeg)': {
|
||||||
topic: function(d) {
|
topic: function(d) {
|
||||||
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif
|
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif
|
||||||
|
Loading…
Reference in New Issue
Block a user