"use strict";
var Log4jsLogger_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Log4jsLogger = void 0;
const tslib_1 = require("tslib");
const codiac_common_1 = require("@codiac.io/codiac-common");
const IBetterLogger_1 = require("@codiac.io/codiac-common/IBetterLogger");
const inversify_1 = require("inversify");
const log4js = require("log4js");
// @injectable()
// export class Log4jsLoggerSettings implements Partial<log4js.Configuration> {
//   appenders?: { [name: string]: log4js.Appender; };
//   categories?: { [name: string]: { appenders: string[]; level: string; enableCallStack?: boolean | undefined; }; };
//   pm2?: boolean | undefined;
//   pm2InstanceVar?: string | undefined;
//   levels?: log4js.Levels | undefined;
//   disableClustering?: boolean | undefined;
// }
let Log4jsLogger = Log4jsLogger_1 = class Log4jsLogger {
    constructor(settings) {
        this.settings = settings;
        this.showing = [IBetterLogger_1.LogLevel.notice]; // TODO:  Remove this from IBetterLogger
        log4js.configure(settings);
        this.logger = log4js.getLogger();
    }
    static bootstrap(ioc, settings) {
        // let defaultAppenders: { [name: string]: log4js.Appender } = {
        // };
        // let defaultCategories: { [name: string]: { appenders: string[], level: string, enableCallStack?: boolean | undefined } } = {
        // };
        let ultimateSettings = settings !== null && settings !== void 0 ? settings : Log4jsLogger_1.DEFAULT_CONFIGURATION;
        ioc.bind(Log4jsLogger_1.SETTINGS_IOC_KEY).toConstantValue(ultimateSettings);
        if (ioc.isBound(codiac_common_1.INTERFACES.IBetterLogger)) {
            ioc.rebind(codiac_common_1.INTERFACES.IBetterLogger).to(Log4jsLogger_1);
        }
        else {
            ioc.bind(codiac_common_1.INTERFACES.IBetterLogger).to(Log4jsLogger_1);
        }
        if (ioc.isBound(codiac_common_1.INTERFACES.ILogger)) {
            ioc.rebind(codiac_common_1.INTERFACES.ILogger).to(Log4jsLogger_1);
        }
        else {
            ioc.bind(codiac_common_1.INTERFACES.ILogger).to(Log4jsLogger_1);
        }
    }
    static mapToLog4jsLevel(level) {
        let log4jsLevel = log4js.levels.INFO;
        if (level !== undefined) {
            switch (level) {
                case IBetterLogger_1.LogLevel.notice:
                    log4jsLevel = log4js.levels.MARK;
                    break;
                case IBetterLogger_1.LogLevel.detail:
                    log4jsLevel = log4js.levels.INFO;
                    break;
                default: log4jsLevel = level;
            }
        }
        return log4jsLevel;
    }
    write(message, level, data) {
        if (data !== undefined) {
            this.logger.log(Log4jsLogger_1.mapToLog4jsLevel(level), message, data);
        }
        else {
            this.logger.log(Log4jsLogger_1.mapToLog4jsLevel(level), message);
        }
    }
    trace(message, data) {
        if (data !== undefined) {
            this.logger.trace(message, data);
        }
        else {
            this.logger.trace(message);
        }
    }
    debug(message, data) {
        if (data !== undefined) {
            this.logger.debug(message, data);
        }
        else {
            this.logger.debug(message);
        }
    }
    detail(message, data) {
        if (data !== undefined) {
            this.logger.info(message, data);
        }
        else {
            this.logger.info(message);
        }
    }
    notice(message, data) {
        if (data !== undefined) {
            this.logger.mark(message, data);
        }
        else {
            this.logger.mark(message);
        }
    }
    warn(message, data) {
        if (data !== undefined) {
            this.logger.warn(message, data);
        }
        else {
            this.logger.warn(message);
        }
    }
    error(message, data) {
        if (data !== undefined) {
            this.logger.error(message, data);
        }
        else {
            this.logger.error(message);
        }
    }
    fatal(message, data) {
        if (data !== undefined) {
            this.logger.fatal(message, data);
        }
        else {
            this.logger.fatal(message);
        }
    }
};
Log4jsLogger.SETTINGS_IOC_KEY = Symbol.for("log4js.Configuration");
/** Applied when no settings doc was provided to the bootstrap() method.  */
Log4jsLogger.DEFAULT_CONFIGURATION = {
    appenders: {},
    categories: {}
};
Log4jsLogger = Log4jsLogger_1 = tslib_1.__decorate([
    (0, inversify_1.injectable)(),
    tslib_1.__param(0, (0, inversify_1.inject)(Log4jsLogger_1.SETTINGS_IOC_KEY)),
    tslib_1.__metadata("design:paramtypes", [Object])
], Log4jsLogger);
exports.Log4jsLogger = Log4jsLogger;
//# sourceMappingURL=log4js-logger.js.map