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 || '';
var regexp = null;
if (nolog) {
if (nolog instanceof RegExp) {
if (type === 'string') {
return nolog.source;
regexp = nolog;
}
return nolog;
} else if (typeof nolog === 'string') {
if (type === 'string') {
return nolog;
if (typeof nolog === 'string') {
regexp = new RegExp(nolog);
}
try {
return new RegExp(nolog);
} catch (ex) {
return null;
if (Array.isArray(nolog)) {
var regexpsAsStrings = nolog.map(
function convertToStrings(o) {
return o.source ? o.source : o;
}
} else if (nolog instanceof Array) {
var regexps = nolog.map(function(o){ return createNoLogCondition(o, 'string'); });
return new RegExp(regexps.join('|'));
);
regexp = new RegExp(regexpsAsStrings.join('|'));
}
}
return regexp;
}
exports.connectLogger = getLogger;