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
* @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;