Permalink
Browse files

fixed the nolog tests

  • Loading branch information...
1 parent 613a077 commit 61078e88ef1f45f3586214faf875aa64b999d01c Gareth Jones committed May 9, 2012
Showing with 84 additions and 85 deletions.
  1. +4 −4 lib/connect-logger.js
  2. +8 −9 lib/levels.js
  3. +72 −72 test/test-nolog.js
View
@@ -45,8 +45,8 @@ function getLogger(logger4js, options) {
// mount safety
if (req._logging) return next();
- // nologs
- if(nolog && nolog.test(req.originalUrl)) return next();
+ // nologs
+ if (nolog && nolog.test(req.originalUrl)) return next();
if (thislogger.isLevelEnabled(level)) {
@@ -80,7 +80,7 @@ function getLogger(logger4js, options) {
}
};
}
-
+
//ensure next gets always called
next();
};
@@ -165,4 +165,4 @@ function createNoLogCondition(nolog, type) {
}
}
-exports.connectLogger = getLogger;
+exports.connectLogger = getLogger;
View
@@ -12,18 +12,17 @@ function Level(level, levelStr) {
*/
function toLevel(sArg, defaultLevel) {
- if (sArg === null) {
- return defaultLevel;
+ if (!sArg) {
+ return defaultLevel;
}
if (typeof sArg == "string") {
- var s = sArg.toUpperCase();
- if (module.exports[s]) {
- return module.exports[s];
- }
- else {
- return defaultLevel;
- }
+ var s = sArg.toUpperCase();
+ if (module.exports[s]) {
+ return module.exports[s];
+ } else {
+ return defaultLevel;
+ }
}
return toLevel(sArg.toString());
View
@@ -40,84 +40,84 @@ function MockResponse(statusCode) {
vows.describe('log4js connect logger').addBatch({
'getConnectLoggerModule': {
- topic: function() {
- var clm = require('../lib/connect-logger');
- return clm;
- },
-
- 'should return a "connect logger" factory' : function(clm) {
- assert.isObject(clm);
- },
+ topic: function() {
+ var clm = require('../lib/connect-logger');
+ return clm;
+ },
- 'nolog String' : {
- topic: function(clm) {
- var ml = new MockLogger();
- var cl = clm.connectLogger(ml, {nolog: "\\.gif"});
- return {cl: cl, ml: ml};
+ 'should return a "connect logger" factory' : function(clm) {
+ assert.isObject(clm);
},
- 'check unmatch url request': {
- topic: function(d){
- var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
- var res = new MockResponse(200);
- d.cl(req, res, function() { });
- 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();
+ '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': {
+ topic: function(d){
+ var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
+ var res = new MockResponse(200);
+ d.cl(req, res, function() { });
+ 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) {
- var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
- var res = new MockResponse(200);
- d.cl(req, res, function() { });
- res.end('chunk', 'encoding');
- return d.ml.messages;
+ var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
+ var res = new MockResponse(200);
+ d.cl(req, res, function() { });
+ res.end('chunk', 'encoding');
+ return d.ml.messages;
}
- , 'check message': function(messages) {
- assert.isArray(messages);
- assert.equal(messages.length, 0);
+ , 'check message': function(messages) {
+ assert.isArray(messages);
+ 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)': {
- topic: function(d){
- var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
- var res = new MockResponse(200);
- d.cl(req, res, function() { });
- 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();
+ '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)': {
+ topic: function(d){
+ var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
+ var res = new MockResponse(200);
+ d.cl(req, res, function() { });
+ 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 (gif)': {
topic: function(d) {
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();
}
},
-
+
'check match url request (gif)': {
topic: function(d) {
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);
}
},
-
+
'check match url request (jpeg)': {
topic: function(d) {
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();
}
},
-
+
'check match url request (gif)': {
topic: function(d) {
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);
}
},
-
+
'check match url request (jpeg)': {
topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif

0 comments on commit 61078e8

Please sign in to comment.