monolog
Version:
Log with Monolog
122 lines (94 loc) • 2.94 kB
JavaScript
// Generated by CoffeeScript 1.6.3
var AbstractHandler, LineFormatter, Logger;
Logger = require('../Logger');
LineFormatter = require('../formatter/LineFormatter');
AbstractHandler = (function() {
/*
Base Handler class providing the Handler structure
*/
function AbstractHandler(level, bubble) {
this.level = level != null ? level : Logger.DEBUG;
this.bubble = bubble != null ? bubble : true;
this.processors = [];
}
/*
Checks whether the given record will be handled by this handler.
This is mostly done for performance reasons, to avoid calling processors for nothing.
Handlers should still check the record levels within handle(), returning false in isHandling()
is no guarantee that handle() will not be called, and isHandling() might not be called
for a given record.
@param {Array} record
@return {Boolean}
*/
AbstractHandler.prototype.isHandling = function(record) {
return record.level >= this.level;
};
/*
handle a record
@param {monolog.Record} record
@param {Function} cb
@return {Boolean}
*/
AbstractHandler.prototype.handle = function(record, cb) {
if (cb instanceof Function) {
cb(void 0, void 0, record, this);
}
return false;
};
/*
handle an array of records
@param {Array<Object>} records
@return {Boolean}
*/
AbstractHandler.prototype.handleBatch = function(records) {
var record, _i, _len;
for (_i = 0, _len = records.length; _i < _len; _i++) {
record = records[_i];
this.handle(record);
}
};
AbstractHandler.prototype.close = function() {};
AbstractHandler.prototype.pushProcessor = function(callback) {
if (callback instanceof Function) {
return this.processors.unshift(callback);
}
};
AbstractHandler.prototype.popProcessor = function() {
this.processors.shift();
return this;
};
AbstractHandler.prototype.setFormatter = function(formatter) {
this.formatter = formatter;
};
AbstractHandler.prototype.getFormatter = function() {
return this.formatter = !this.formatter ? new LineFormatter : this.formatter;
};
AbstractHandler.prototype.setLevel = function(level) {
this.level = level;
};
AbstractHandler.prototype.getLevel = function() {
return this.level;
};
AbstractHandler.prototype.setBubble = function(bubble) {
this.bubble = bubble;
};
AbstractHandler.prototype.getBubble = function() {
return this.bubble;
};
AbstractHandler.prototype.processRecord = function(record) {
var processor, _i, _len, _ref;
if (this.processors) {
_ref = this.processors;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
processor = _ref[_i];
record = processor(record);
}
}
return record;
};
return AbstractHandler;
})();
module.exports = AbstractHandler;
/*
//@ sourceMappingURL=AbstractHandler.map
*/