simplified createNoLogCondition

This commit is contained in:
Gareth Jones 2013-06-05 08:37:27 +10:00
parent 6368de1094
commit 7ca517b5ed

View File

@ -145,9 +145,7 @@ function format(str, req, res) {
* @param {String} nolog * @param {String} nolog
* @return {RegExp} * @return {RegExp}
* @api private * @api private
*/ *
/**
* syntax * syntax
* 1. String * 1. String
* 1.1 "\\.gif" * 1.1 "\\.gif"
@ -169,27 +167,28 @@ function format(str, req, res) {
* SAME AS "\\.jpg|\\.png|\\.gif" * SAME AS "\\.jpg|\\.png|\\.gif"
*/ */
function createNoLogCondition(nolog, type) { function createNoLogCondition(nolog, type) {
if (!nolog) return null; var regexp = null;
type = type || '';
if (nolog) {
if (nolog instanceof RegExp) { if (nolog instanceof RegExp) {
if (type === 'string') { regexp = nolog;
return nolog.source; }
if (typeof nolog === 'string') {
regexp = new RegExp(nolog);
} }
return nolog;
} else if (typeof nolog === 'string') { if (Array.isArray(nolog)) {
if (type === 'string') { var regexpsAsStrings = nolog.map(
return nolog; function convertToStrings(o) {
return o.source ? o.source : o;
}
);
regexp = new RegExp(regexpsAsStrings.join('|'));
} }
try { }
return new RegExp(nolog);
} catch (ex) { return regexp;
return null;
}
} else if (nolog instanceof Array) {
var regexps = nolog.map(function(o){ return createNoLogCondition(o, 'string'); });
return new RegExp(regexps.join('|'));
}
} }
exports.connectLogger = getLogger; exports.connectLogger = getLogger;