"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ConsoleLogger_1 = require("../channels/ConsoleLogger");
const NoOpLogger_1 = require("../channels/NoOpLogger");
const LoggerImpl_1 = require("./LoggerImpl");
const LogLevel_1 = require("./LogLevel");
exports.noop = new NoOpLogger_1.NoOpLogger();
const defaultChannel = new ConsoleLogger_1.ConsoleLogger();
/**
 * Creates and holds all the loggers
 */
class LoggerFactory {
    static getLogger(loggerName) {
        let found = this.loggers.find((logger) => logger.name === loggerName);
        if (!found) {
            found = instanciateLogger(loggerName, LoggerFactory.defaultLevel, defaultChannel);
        }
        return found;
    }
    static for(loggerName) {
        return new LoggerFactorySyntax(loggerName);
    }
}
LoggerFactory.defaultLevel = LogLevel_1.LogLevel.INFO;
LoggerFactory.loggers = [];
exports.LoggerFactory = LoggerFactory;
const instanciateLogger = (loggerName, level, channel) => {
    const logger = new LoggerImpl_1.LoggerImpl(loggerName, level, channel);
    LoggerFactory.loggers.push(logger);
    return logger;
};
class LoggerFactorySyntax {
    constructor(loggerName) {
        this.loggerName = loggerName;
    }
    get() {
        const found = LoggerFactory.loggers.find((logger) => logger.name === this.loggerName);
        if (!found) {
            const level = this._level ? this._level : LoggerFactory.defaultLevel;
            const channel = this.channel ? this.channel : defaultChannel;
            return instanciateLogger(this.loggerName, level, channel);
        }
        if (this._level) {
            found.level = this._level;
        }
        if (this.channel) {
            found.channel = this.channel;
        }
        return found;
    }
    on(channel) {
        this.channel = channel;
        return this;
    }
    level(level) {
        this._level = level;
        return this;
    }
}
exports.LoggerFactorySyntax = LoggerFactorySyntax;
//# sourceMappingURL=LoggerFactory.js.map