"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Category = void 0;
const express_winston_1 = __importDefault(require("express-winston"));
const winston_1 = __importDefault(require("winston"));
const config_1 = __importDefault(require("config"));
const path_1 = __importDefault(require("path"));
var Category;
(function (Category) {
    Category["Cli"] = "cli";
    Category["DealPreparationService"] = "deal_preparation_service";
    Category["Database"] = "database";
    Category["DealPreparationWorker"] = "deal_preparation_worker";
    Category["IndexService"] = "index_service";
    Category["HttpHostingService"] = "http_hosting_service";
    Category["DealTrackingService"] = "deal_tracking_service";
})(Category = exports.Category || (exports.Category = {}));
const container = new winston_1.default.Container();
const loggerFormat = (category, colorize) => {
    const formats = [
        winston_1.default.format.timestamp(),
        winston_1.default.format.splat(),
        winston_1.default.format.label({
            label: category
        }),
        winston_1.default.format.printf(({ level, message, label, timestamp, ...others }) => {
            return `${timestamp} [${label}] ${level}: ${message} - ${JSON.stringify(others)}`;
        })
    ];
    if (colorize) {
        formats.push(winston_1.default.format.colorize());
    }
    return winston_1.default.format.combine(...formats);
};
Object.values(Category).forEach(category => {
    const transports = [];
    transports.push(new winston_1.default.transports.Console({
        level: config_1.default.has('logging.console_level') ? config_1.default.get('logging.console_level') : 'info',
        format: loggerFormat(category, true)
    }));
    if (config_1.default.has('logging.file_level') && config_1.default.has('logging.file_path')) {
        transports.push(new winston_1.default.transports.File({
            level: config_1.default.get('logging.file_level'),
            dirname: path_1.default.resolve(process.env.NODE_CONFIG_DIR, config_1.default.get('logging.file_path')),
            filename: `${category}.log`,
            format: loggerFormat(category, false)
        }));
    }
    container.add(category, {
        transports
    });
});
class Logger {
    static getLogger(category) {
        return container.get(category);
    }
    static getExpressLogger(category) {
        const transports = [];
        transports.push(new winston_1.default.transports.Console({
            level: config_1.default.has('logging.console_level') ? config_1.default.get('logging.console_level') : 'info',
            format: loggerFormat(category, true)
        }));
        if (config_1.default.has('logging.file_level') && config_1.default.has('logging.file_path')) {
            transports.push(new winston_1.default.transports.File({
                level: config_1.default.get('logging.file_level'),
                dirname: path_1.default.resolve(process.env.NODE_CONFIG_DIR, config_1.default.get('logging.file_path')),
                filename: `${category}.log`,
                format: loggerFormat(category, false)
            }));
        }
        return express_winston_1.default.logger({
            transports,
            meta: true,
            msg: 'HTTP {{req.method}} {{req.url}}',
            expressFormat: true,
            colorize: true,
            ignoreRoute: (_req, _res) => false
        });
    }
}
exports.default = Logger;
//# sourceMappingURL=Logger.js.map