@log4js2/core
Version:
log4js2 is a fast and lightweight logging library that enables logging flexibility within JavaScript/TypeScript applications, similar to Apache's [Log4j2 library](https://logging.apache.org/log4j/2.x/). It can also serve as a drop-in replacement for log4
67 lines (66 loc) • 2.48 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var filter_1 = require("../filter");
var log_filter_action_1 = require("../filter/log.filter.action");
var AppenderWrapper = /** @class */ (function () {
function AppenderWrapper(appender, _config) {
this._config = _config;
this._appender = new appender(_config.config);
this._appender.setLayout(_config.layout);
this._isPassThrough = (!_config || !_config.filters || _config.filters.length === 0);
if (!this._isPassThrough) {
this._filters = _config.filters.map(function (value) {
return {
filter: (value.filter instanceof Function) ? new value.filter(value.config) :
new (filter_1.getFilter(value.filter))(value.config),
config: value.config,
onMatch: value.onMatch,
onMismatch: value.onMismatch
};
});
}
else {
this._filters = [];
}
}
Object.defineProperty(AppenderWrapper.prototype, "appender", {
get: function () {
return this._appender;
},
enumerable: true,
configurable: true
});
AppenderWrapper.prototype.append = function (event) {
if (this.isMatch(event)) {
this._appender.append(event);
}
};
AppenderWrapper.prototype.isMatch = function (event) {
return this._isPassThrough || this._isMatch(event);
};
AppenderWrapper.prototype._isMatch = function (event) {
var item;
var count = this._filters.length;
for (var i = 0; i < count; i++) {
item = this._filters[i];
if (!item.filter.isMatch(event)) {
if (item.onMismatch === log_filter_action_1.LogFilterAction.DENY) {
return false;
}
else if (item.onMismatch === log_filter_action_1.LogFilterAction.ALLOW) {
return true;
}
}
else {
if (item.onMatch === log_filter_action_1.LogFilterAction.DENY) {
return false;
}
else if (item.onMatch === log_filter_action_1.LogFilterAction.ALLOW) {
return true;
}
}
}
return true;
};
return AppenderWrapper;
}());
exports.AppenderWrapper = AppenderWrapper;