typescript-logging
Version:
Library for logging, written in typescript, can be used by normal es5+ javascript as well.
93 lines • 4.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var LoggerOptions_1 = require("../LoggerOptions");
/**
* Defines a LogGroupRule, this allows you to either have everything configured the same way
* or for example loggers that start with name model. It allows you to group loggers together
* to have a certain loglevel and other settings. You can configure this when creating the
* LoggerFactory (which accepts multiple LogGroupRules).
*/
var LogGroupRule = (function () {
/**
* Create a LogGroupRule. Basically you define what logger name(s) match for this group, what level should be used what logger type (where to log)
* and what format to write in. If the loggerType is custom, then the callBackLogger must be supplied as callback function to return a custom logger.
* @param regExp Regular expression, what matches for your logger names for this group
* @param level LogLevel
* @param logFormat LogFormat
* @param loggerType Type of logger, if Custom, make sure to implement callBackLogger and pass in, this will be called so you can return your own logger.
* @param callBackLogger Callback function to return a new clean custom logger (yours!)
*/
function LogGroupRule(regExp, level, logFormat, loggerType, callBackLogger) {
if (logFormat === void 0) { logFormat = new LoggerOptions_1.LogFormat(); }
if (loggerType === void 0) { loggerType = LoggerOptions_1.LoggerType.Console; }
if (callBackLogger === void 0) { callBackLogger = null; }
this._formatterLogMessage = null;
this._regExp = regExp;
this._level = level;
this._logFormat = logFormat;
this._loggerType = loggerType;
this._callBackLogger = callBackLogger;
}
Object.defineProperty(LogGroupRule.prototype, "regExp", {
get: function () {
return this._regExp;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LogGroupRule.prototype, "level", {
get: function () {
return this._level;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LogGroupRule.prototype, "loggerType", {
get: function () {
return this._loggerType;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LogGroupRule.prototype, "logFormat", {
get: function () {
return this._logFormat;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LogGroupRule.prototype, "callBackLogger", {
get: function () {
return this._callBackLogger;
},
enumerable: true,
configurable: true
});
Object.defineProperty(LogGroupRule.prototype, "formatterLogMessage", {
/**
* Get the formatterLogMessage function, see comment on the setter.
* @returns {((message:LogMessage)=>string)|null}
*/
get: function () {
return this._formatterLogMessage;
},
/**
* Set the default formatterLogMessage function, if set it is applied to all type of loggers except for a custom logger.
* By default this is null (not set). You can assign a function to allow custom formatting of a log message.
* Each log message will call this function then and expects your function to format the message and return a string.
* Will throw an error if you attempt to set a formatterLogMessage if the LoggerType is custom.
* @param value The formatter function, or null to reset it.
*/
set: function (value) {
if (value !== null && this._loggerType === LoggerOptions_1.LoggerType.Custom) {
throw new Error("You cannot specify a formatter for log messages if your loggerType is Custom");
}
this._formatterLogMessage = value;
},
enumerable: true,
configurable: true
});
return LogGroupRule;
}());
exports.LogGroupRule = LogGroupRule;
//# sourceMappingURL=LogGroupRule.js.map