{"size": 1179, "ext": "js", "max_stars_repo_path": "core/Filterer.js", "max_stars_repo_name": "jose-pleonasm/py-logging", "max_stars_repo_stars_event_min_datetime": "2015-10-14T13:48:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-10T08:24:56.000Z", "max_issues_repo_path": "core/Filterer.js", "max_issues_repo_name": "jose-pleonasm/py-logging", "max_issues_repo_issues_event_min_datetime": "2016-07-06T12:22:35.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-08T10:37:54.000Z", "max_forks_repo_path": "core/Filterer.js", "max_forks_repo_name": "jose-pleonasm/py-logging", "max_forks_repo_forks_event_min_datetime": "2021-02-09T22:59:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-09T22:59:43.000Z"}
{"max_stars_count": 18, "max_issues_count": 27, "max_forks_count": 1, "avg_line_length": 20.6842105263, "max_line_length": 80, "alphanum_fraction": 0.6480067854}

/**
 * A base class for loggers and handlers which allows them to share common code.
 *
 * @constructor Filterer
 */
function Filterer() {
	/**
	 * Array of set filters.
	 *
	 * @private
	 * @type {Array<(Filter|Function)>}
	 */
	this._filters = [];
}

/**
 * @param {(Filter|Function)} filter
 */
Filterer.prototype.addFilter = function(filter) {
	if (typeof filter !== 'object' && typeof filter !== 'function') {
		throw new Error('Argument filter is not an object nor a function.');
	}

	this._filters.push(filter);
};

/**
 * @param  {(Filter|Function)} filter
 */
Filterer.prototype.removeFilter = function(filter) {
	var index = this._filters.indexOf(filter);
	if (index > -1) {
		this._filters.splice(index, 1);
	}
};

/**
 * @param  {module:py-logging.LogRecord} record
 * @return {boolean} Returns false if specified record is not supposed
 * 	to be processed. True otherwise.
 */
Filterer.prototype.filter = function(record) {
	for (var i = 0, len = this._filters.length; i < len; i++) {
		var f = this._filters[i];
		var result = f.filter ? f.filter.call(f, record) : f(record);

		if (!result) {
			return false;
		}
	}
	return true;
};


module.exports = Filterer;
