All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.config.logging.default-momento-logger.js Maven / Gradle / Ivy

The newest version!
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultMomentoLogger = exports.DefaultMomentoLoggerFactory = exports.DefaultMomentoLoggerLevel = void 0;
const printf = require("../../internal/vendor/printf/printf");
var DefaultMomentoLoggerLevel;
(function (DefaultMomentoLoggerLevel) {
    DefaultMomentoLoggerLevel[DefaultMomentoLoggerLevel["TRACE"] = 5] = "TRACE";
    DefaultMomentoLoggerLevel[DefaultMomentoLoggerLevel["DEBUG"] = 10] = "DEBUG";
    DefaultMomentoLoggerLevel[DefaultMomentoLoggerLevel["INFO"] = 20] = "INFO";
    DefaultMomentoLoggerLevel[DefaultMomentoLoggerLevel["WARN"] = 30] = "WARN";
    DefaultMomentoLoggerLevel[DefaultMomentoLoggerLevel["ERROR"] = 40] = "ERROR";
})(DefaultMomentoLoggerLevel = exports.DefaultMomentoLoggerLevel || (exports.DefaultMomentoLoggerLevel = {}));
class DefaultMomentoLoggerFactory {
    constructor(level = DefaultMomentoLoggerLevel.INFO) {
        this.level = level;
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    getLogger(loggerName) {
        return new DefaultMomentoLogger(loggerName, this.level);
    }
}
exports.DefaultMomentoLoggerFactory = DefaultMomentoLoggerFactory;
class DefaultMomentoLogger {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    constructor(loggerName, level) {
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
        this.loggerName =
            typeof loggerName === 'string' || loggerName instanceof String
                ? loggerName
                : // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
                    loggerName.constructor.name;
        this.level = level;
    }
    trace(msg, ...args) {
        if (this.level > DefaultMomentoLoggerLevel.TRACE) {
            return;
        }
        this.outputMessage(console.log, DefaultMomentoLoggerLevel.TRACE, msg, args);
    }
    debug(msg, ...args) {
        if (this.level > DefaultMomentoLoggerLevel.DEBUG) {
            return;
        }
        this.outputMessage(console.log, DefaultMomentoLoggerLevel.DEBUG, msg, args);
    }
    info(msg, ...args) {
        if (this.level > DefaultMomentoLoggerLevel.INFO) {
            return;
        }
        this.outputMessage(console.log, DefaultMomentoLoggerLevel.INFO, msg, args);
    }
    warn(msg, ...args) {
        if (this.level > DefaultMomentoLoggerLevel.WARN) {
            return;
        }
        this.outputMessage(console.warn, DefaultMomentoLoggerLevel.WARN, msg, args);
    }
    error(msg, ...args) {
        if (this.level > DefaultMomentoLoggerLevel.ERROR) {
            return;
        }
        this.outputMessage(console.error, DefaultMomentoLoggerLevel.ERROR, msg, args);
    }
    outputMessage(outputFn, level, msg, args) {
        outputFn(printf('[%s] %s (Momento: %s): %s', new Date().toISOString(), DefaultMomentoLoggerLevel[level], this.loggerName, printf(msg, ...args)));
    }
}
exports.DefaultMomentoLogger = DefaultMomentoLogger;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdC1tb21lbnRvLWxvZ2dlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb25maWcvbG9nZ2luZy9kZWZhdWx0LW1vbWVudG8tbG9nZ2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUlBLDhEQUErRDtBQUUvRCxJQUFZLHlCQU1YO0FBTkQsV0FBWSx5QkFBeUI7SUFDbkMsMkVBQVMsQ0FBQTtJQUNULDRFQUFVLENBQUE7SUFDViwwRUFBUyxDQUFBO0lBQ1QsMEVBQVMsQ0FBQTtJQUNULDRFQUFVLENBQUE7QUFDWixDQUFDLEVBTlcseUJBQXlCLEdBQXpCLGlDQUF5QixLQUF6QixpQ0FBeUIsUUFNcEM7QUFFRCxNQUFhLDJCQUEyQjtJQUV0QyxZQUNFLFFBQW1DLHlCQUF5QixDQUFDLElBQUk7UUFFakUsSUFBSSxDQUFDLEtBQUssR0FBRyxLQUFLLENB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zdHJpbmcsIC4uLmFyZ3M6IHVua25vd25bXSk6IHZvaWQge1xuICAgIGlmICh0aGlzLmxldmVsID4gRGVmYXVsdE1vbWVudG9Mb2dnZXJMZXZlbC5FUlJPUikge1xuICAgICAgcmV0dXJuO1xuICAgIH1cbiAgICB0aGlzLm91dHB1dE1lc3NhZ2UoXG4gICAgICBjb25zb2xlLmVycm9yLFxuICAgICAgRGVmYXVsdE1vbWVudG9Mb2dnZXJMZXZlbC5FUlJPUixcbiAgICAgIG1zZyxcbiAgICAgIGFyZ3NcbiAgICApO1xuICB9XG5cbiAgcHJpdmF0ZSBvdXRwdXRNZXNzYWdlKFxuICAgIG91dHB1dEZuOiAob3V0cHV0OiBzdHJpbmcpID0+IHZvaWQsXG4gICAgbGV2ZWw6IERlZmF1bHRNb21lbnRvTG9nZ2VyTGV2ZWwsXG4gICAgbXNnOiBzdHJpbmcsXG4gICAgYXJnczogdW5rbm93bltdXG4gICkge1xuICAgIG91dHB1dEZuKFxuICAgICAgcHJpbnRmKFxuICAgICAgICAnWyVzXSAlcyAoTW9tZW50bzogJXMpOiAlcycsXG4gICAgICAgIG5ldyBEYXRlKCkudG9JU09TdHJpbmcoKSxcbiAgICAgICAgRGVmYXVsdE1vbWVudG9Mb2dnZXJMZXZlbFtsZXZlbF0sXG4gICAgICAgIHRoaXMubG9nZ2VyTmFtZSxcbiAgICAgICAgcHJpbnRmKG1zZywgLi4uYXJncylcbiAgICAgIClcbiAgICApO1xuICB9XG59XG4iXX0=




© 2015 - 2024 Weber Informatics LLC | Privacy Policy