From 7ca517b5edf07ba9551ee1bcf2e41df6c07c5889 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Wed, 5 Jun 2013 08:37:27 +1000 Subject: [PATCH] simplified createNoLogCondition --- lib/connect-logger.js | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/connect-logger.js b/lib/connect-logger.js index 454ee4a..25f2335 100644 --- a/lib/connect-logger.js +++ b/lib/connect-logger.js @@ -145,9 +145,7 @@ function format(str, req, res) { * @param {String} nolog * @return {RegExp} * @api private - */ - -/** + * * syntax * 1. String * 1.1 "\\.gif" @@ -169,27 +167,28 @@ function format(str, req, res) { * SAME AS "\\.jpg|\\.png|\\.gif" */ function createNoLogCondition(nolog, type) { - if (!nolog) return null; - type = type || ''; - - if (nolog instanceof RegExp) { - if (type === 'string') { - return nolog.source; + var regexp = null; + + if (nolog) { + if (nolog instanceof RegExp) { + regexp = nolog; + } + + if (typeof nolog === 'string') { + regexp = new RegExp(nolog); } - return nolog; - } else if (typeof nolog === 'string') { - if (type === 'string') { - return nolog; + + if (Array.isArray(nolog)) { + var regexpsAsStrings = nolog.map( + function convertToStrings(o) { + return o.source ? o.source : o; + } + ); + regexp = new RegExp(regexpsAsStrings.join('|')); } - try { - return new RegExp(nolog); - } catch (ex) { - return null; - } - } else if (nolog instanceof Array) { - var regexps = nolog.map(function(o){ return createNoLogCondition(o, 'string'); }); - return new RegExp(regexps.join('|')); - } + } + + return regexp; } exports.connectLogger = getLogger;