plogger-sdk
Version:
Typescript based frontend logging library compatible with multiple transports and JS/TS frameworks
45 lines • 1.59 kB
JavaScript
import { logLevel } from "./logLevel";
var BaseLogger = /** @class */ (function () {
function BaseLogger() {
/**
* defines the enum keys for standardized messaging.
*/
this.logEnums = {};
this.formatter = "[{{levelName}}] {{timestampLocalIso}} {{scope}} : {{rawMessage}}";
this.level = logLevel.Debug;
}
/**
* sets the threshold level on which any log called with a higher rank / lower priority will be ignored.
* @param log_level logLevel
*/
BaseLogger.prototype.setLevel = function (log_level) {
this.level = log_level;
}; //change this argument type to logLevelstrings
BaseLogger.prototype.getLevel = function () {
return this.level;
};
/**
* sets a formatter to the log message for the browser
* @param formatter string
*/
BaseLogger.prototype.setFormatter = function (formatter) {
this.formatter = formatter;
};
/**
* Generates the formatted log message.
* @param log - logRecord
* @returns
*/
BaseLogger.prototype.formatLog = function (log) {
var placeholderValues = log.getFormatPlaceholders();
var current_formatter = log.formatter != null ? log.formatter : this.formatter;
return current_formatter.replace(/{{(.+?)}}/g, function (_, placeholder) {
return placeholderValues[placeholder] != null
? placeholderValues[placeholder]
: "";
});
};
return BaseLogger;
}());
export { BaseLogger };
//# sourceMappingURL=Logger.js.map