"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "LoggerService", {
    enumerable: true,
    get: function() {
        return LoggerService;
    }
});
const _winston = /*#__PURE__*/ _interop_require_default(require("winston"));
const _path = require("path");
const _luxon = require("luxon");
const _serverconstants = require("../server.constants");
const _fsutils = require("../utils/fs.utils");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const dtFormat = new Intl.DateTimeFormat("en-GB", {
    timeStyle: "medium",
    dateStyle: "short",
    timeZone: "UTC"
});
const dateFormat = ()=>{
    return dtFormat.format(new Date());
};
class LoggerService {
    name;
    logger;
    constructor(name, enableFileLogs = true, logFilterLevel = ""){
        const isProd = process.env[_serverconstants.AppConstants.NODE_ENV_KEY] === _serverconstants.AppConstants.defaultProductionEnv;
        const isTest = process.env[_serverconstants.AppConstants.NODE_ENV_KEY] === _serverconstants.AppConstants.defaultTestEnv;
        if (!logFilterLevel) {
            logFilterLevel = isProd || isTest ? "warn" : "info";
        }
        const date = _luxon.DateTime.now().toISODate();
        this.name = name;
        this.logger = _winston.default.createLogger({
            transports: [
                new _winston.default.transports.Console({
                    level: logFilterLevel
                }),
                ...enableFileLogs ? [
                    new _winston.default.transports.File({
                        level: isTest ? "warn" : "info",
                        filename: (0, _path.join)((0, _fsutils.superRootPath)(), _serverconstants.AppConstants.defaultLogsFolder, `${_serverconstants.AppConstants.logAppName}-${date}.log`),
                        maxsize: 5000000,
                        maxFiles: 5
                    })
                ] : []
            ],
            format: _winston.default.format.printf((info)=>{
                const level = info.level.toUpperCase();
                const date = dateFormat();
                let message = `${date} | ${level} | ${name} | ${info.message}`;
                message = info.meta ? message + ` - ${JSON.stringify(info.meta)}` : message;
                return message;
            })
        });
    }
    log(message, meta) {
        this.logger.log("info", message, {
            meta
        });
    }
    warn(message, meta) {
        this.logger.log("warn", message, {
            meta
        });
    }
    debug(message, meta) {
        this.logger.log("debug", message, {
            meta
        });
    }
    error(message, meta) {
        this.logger.log("error", message, {
            meta
        });
    }
}

//# sourceMappingURL=logger.js.map