"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const winston = require("winston");
const DailyRotateFile = require('winston-daily-rotate-file');
const fs = require("fs");
const colors = require("colors/safe");
const util = require("util");
const Cryptr = require('cryptr');
//import stripAnsi from 'strip-ansi';
/* let stripAnsi;
(async () => {
    //import {stripAnsi} from 'strip-ansi';
    stripAnsi = await import('strip-ansi');
})();
// */
//let defaultConfig = require("../config/config");
const config_1 = require("../config/config");
const Utils_js_1 = require("./Utils.js");
const LevelLogs_js_1 = require("./LevelLogs.js");
const path_1 = require("path");
const LOG_ID = "LOGS - ";
const tsFormat = (p_date = undefined) => {
    //let date = new Date(p_date);
    let date = new Date();
    return date.toLocaleDateString() + " " + date.toLocaleTimeString() + ":" + date.getMilliseconds() + " [" + date.valueOf() + "]";
    //return date.valueOf();
};
const myFormat = winston.format.printf((info) => {
    // 12/03/2025 10:00:11:846 [1741770011846]
    //return `${info.timestamp} [${info._processInfo.pid}] ${info.level}: ${info.message}`;
    return `${tsFormat()} - ${info.level}: ${info.message}`;
    //return `${info.timestamp} [` + tsFormat(info.timestamp) + `] - ${info.level}: ${info.message}`;
});
const myFormatNoColors = winston.format.printf(info => {
    //return `${info.timestamp} [` + tsFormat(info.timestamp) + `] - ${info.level}: ${info.message}`;
    return `${tsFormat()} - ${info.level}: ${info.message}`;
    // The following code is necessary when the colors lib disabled.
    //return `${tsFormat()}` + ' - ' + stripAnsi(info.level) + ':' + stripAnsi(info.message);
});
class Logger {
    get areasLogs() {
        return this._areasLogs;
    }
    set areasLogs(value) {
        this._areasLogs = value;
    }
    // public levels: { debug: number; warning: number; error: number;   "http": number, "xmpp": number; info: number , "warn": number, "trace": number, "internal": number, "internalerror": number};
    get logEventEmitter() {
        return this._logEventEmitter;
    }
    set logEventEmitter(value) {
        this._logEventEmitter = value;
    }
    constructor(config) {
        this.enableEncryptedLogs = false;
        this.stripStringForLogs = function (value) {
            return this._logger?.stripStringForLogs(value);
        };
        this.argumentsToString = this.argumentsToStringFull;
        let self = this;
        const cryptr = new Cryptr('rainbow-node-sdk-1654341354345486797943542318461318730123013');
        winston.addColors(LevelLogs_js_1.LEVELSCOLORS);
        this.colors = colors;
        this.colors.setTheme({
            silly: 'rainbow',
            input: 'grey',
            verbose: 'cyan',
            prompt: 'grey',
            info: 'green',
            data: 'grey',
            help: 'cyan',
            warn: 'yellow',
            debug: 'blue',
            error: 'red',
            xmpp: "cyan",
            events: ['magenta', 'underline', 'italic'],
            eventsEmitter: ['cyan', 'underline', 'italic']
        });
        let welcome = () => {
            let fullVersion = "";
            try {
                //let content = fs.readFileSync(path.join(__dirname, "../package.json"));
                // If using CommonJS, use __dirname
                // If using ES modules:
                const currentFileUrl = __dirname;
                const currentDir = (0, path_1.dirname)(currentFileUrl);
                //const currentFileUrl = import.meta.url;
                //const currentDir = dirname(fileURLToPath(currentFileUrl));
                const packageJsonPath = (0, Utils_js_1.findPackageJson)(currentDir);
                if (packageJsonPath) {
                    console.log(`Found package.json at: ${packageJsonPath}`);
                    let content = fs.readFileSync(packageJsonPath);
                    let packageJSON = JSON.parse(content);
                    fullVersion = packageJSON.version;
                }
            }
            catch (err) {
                console.log("CATCH Error !!! in welcome : ", err);
            }
            this._logger.log("info", LOG_ID + "------------------------------------------------");
            this._logger.log("info", LOG_ID + "Welcome to the " + this.colors.magenta("ALE Rainbow SDK for Node.JS") + "");
            this._logger.log("info", LOG_ID + "Where Everything connects");
            this._logger.log("info", LOG_ID + "Support: Send message to Emily using #support #api");
            this._logger.log("info", LOG_ID + "Node Version : ", process.versions.node, ", Rainbow Node SDK Version : ", fullVersion);
            this._logger.log("info", LOG_ID + "------------------------------------------------");
            this._logger.log("internal", LOG_ID + "(constructor) : ", this.colors.italic(this.colors.red(" \n\
     * \"system-dev\" section in logs is activated!!! \n\
    Note that it is for DEVELOPPEMENT ONLY, no production system should use it : \n\
     * \"internals\" config property is for logs level of debug + unsensored data. \n\
    Warning password and so on can be logs. \n    " +
                that.colors.red.underline("***    IT SHOULD ONLY BE USED IN DEVELOPPEMENT ENVIRONEMENT !!!    ***"))));
            this._logger.log("info", LOG_ID + this.colors[LevelLogs_js_1.LEVELSCOLORS.error]("error level color : " + LevelLogs_js_1.LEVELSCOLORS.error));
            this._logger.log("info", LOG_ID + this.colors[LevelLogs_js_1.LEVELSCOLORS.warn]("warn level color : " + LevelLogs_js_1.LEVELSCOLORS.warn));
            this._logger.log("info", LOG_ID + this.colors[LevelLogs_js_1.LEVELSCOLORS.info]("info level color : " + LevelLogs_js_1.LEVELSCOLORS.info));
            this._logger.log("info", LOG_ID + this.colors[LevelLogs_js_1.LEVELSCOLORS.trace]("trace level color : " + LevelLogs_js_1.LEVELSCOLORS.trace));
            this._logger.log("info", LOG_ID + this.colors[LevelLogs_js_1.LEVELSCOLORS.http]("http level color : " + LevelLogs_js_1.LEVELSCOLORS.http));
            this._logger.log("info", LOG_ID + this.colors[LevelLogs_js_1.LEVELSCOLORS.xmpp]("xmpp level color : " + LevelLogs_js_1.LEVELSCOLORS.xmpp));
            this._logger.log("info", LOG_ID + this.colors[LevelLogs_js_1.LEVELSCOLORS.debug]("debug level color : " + LevelLogs_js_1.LEVELSCOLORS.debug));
            this._logger.log("info", LOG_ID + this.colors[LevelLogs_js_1.LEVELSCOLORS.internalerror]("internalerror level color : " + LevelLogs_js_1.LEVELSCOLORS.internalerror));
            this._logger.log("info", LOG_ID + this.colors[LevelLogs_js_1.LEVELSCOLORS.internal]("internal level color : " + LevelLogs_js_1.LEVELSCOLORS.internal));
        };
        let logs = config_1.config.logs;
        let logDir = logs.path;
        self.logLevel = logs.level;
        self.logColor = logs.color;
        let logHttp = logs["system-dev"].http;
        let logInternals = logs["system-dev"].internals;
        let logFormat = myFormat;
        let zippedArchive = logs.zippedArchive;
        let maxSize = logs.maxSize;
        let maxFiles = logs.maxFiles;
        let enableConsoleLog = true;
        let enableFileLog = false;
        let enableEventsLogs = false;
        let enableEncryptedLogs = false;
        let customFileName = "";
        /*
        this.argumentsToString = this.argumentsToStringReduced;
        // */
        // No configuration for file --> Don't store logs in file
        if (!("logs" in config)) {
            enableFileLog = false;
        }
        if (("logs" in config) && ("color" in config.logs)) {
            self.logColor = config.logs.color;
        }
        if (("logs" in config) && ("system-dev" in config.logs) && ("http" in config.logs["system-dev"])) {
            logHttp = config.logs["system-dev"].http;
        }
        if (("logs" in config) && ("system-dev" in config.logs) && ("internals" in config.logs["system-dev"])) {
            logInternals = config.logs["system-dev"].internals;
        }
        if (!self.logColor) {
            this.colors?.disable();
            logFormat = myFormatNoColors;
        }
        else {
            this.colors?.enable();
            logFormat = myFormat;
        }
        // Check for console log
        if (("logs" in config) && ("enableConsoleLogs" in config.logs) && config.logs.enableConsoleLogs) {
            enableConsoleLog = true;
        }
        else {
            enableConsoleLog = false;
        }
        // Check for file log
        if (("logs" in config) && ("enableFileLogs" in config.logs) && config.logs.enableFileLogs) {
            enableFileLog = true;
        }
        else {
            enableFileLog = false;
        }
        // Check for events log
        if (("logs" in config) && ("enableEventsLogs" in config.logs) && config.logs.enableEventsLogs) {
            enableEventsLogs = true;
        }
        else {
            enableEventsLogs = false;
        }
        // Check for Encryption of stanza in log
        if (("logs" in config) && ("enableEncryptedLogs" in config.logs)) {
            if (config.logs.enableEncryptedLogs == false) {
                enableEncryptedLogs = false;
            }
            else {
                enableEncryptedLogs = true;
            }
            this.enableEncryptedLogs = enableEncryptedLogs;
        }
        // Set Path for log file
        if (enableFileLog) {
            if (("logs" in config) && ("file" in config.logs) && ("path" in config.logs.file)) {
                logDir = config.logs.file.path;
            }
        }
        if (("logs" in config) && ("level" in config.logs)) {
            self.logLevel = config.logs.level;
        }
        if (("logs" in config) && ("internals" in config.logs)) {
            logInternals = config.logs.internals;
        }
        if (enableFileLog) {
            //Set the Level for log file
            if (("logs" in config) && ("file" in config.logs) && ("level" in config.logs.file)) {
                self.logLevel = config.logs.file.level;
            }
            //Set the zippedArchive for log file
            if (("logs" in config) && ("file" in config.logs) && ("zippedArchive" in config.logs.file)) {
                zippedArchive = config.logs.file.zippedArchive;
            }
            //Set the zippedArchive for log file
            if (("logs" in config) && ("file" in config.logs) && ("maxSize" in config.logs.file)) {
                maxSize = config.logs.file.maxSize;
            }
            //Set the zippedArchive for log file
            if (("logs" in config) && ("file" in config.logs) && ("maxFiles" in config.logs.file)) {
                maxFiles = config.logs.file.maxFiles;
            }
            // Check and create the directory for logging
            if (!fs.existsSync(logDir)) {
                try {
                    fs.mkdirSync(config.logs.file.path);
                }
                catch (err) {
                    console.log("Can't create the directoy for logging... File logs will be disabled");
                    console.log("Error", err);
                    enableFileLog = false;
                }
            }
        }
        if (config && config.logs && config.logs.areas) {
            self._areasLogs = config.logs.areas;
        }
        else {
            self._areasLogs = new LevelLogs_js_1.LogLevelAreas(self.logLevel, false, false, false);
            if (self.logLevel === LevelLogs_js_1.LEVELSNAMES.DEBUG) {
                self._areasLogs.showServicesApiLogs();
            }
            if (self.logLevel === LevelLogs_js_1.LEVELSNAMES.INTERNAL) {
                self._areasLogs.showServicesApiLogs(true);
                self._areasLogs.showRESTLogs(self.logLevel);
                self._areasLogs.showEventsLogs(self.logLevel);
            }
        }
        let that = this;
        this._winston = {};
        this._logger = {};
        this._logger.customLabel = "";
        this._logger.logHttp = logHttp;
        this._logger.argumentsToString = that.argumentsToString;
        this._logger.enableEncryptedLogs = that.enableEncryptedLogs;
        if (("logs" in config) && ("customLabel" in config.logs)) {
            this._logger.customLabel = config.logs.customLabel + " - ";
        }
        if (enableFileLog) {
            if (("logs" in config) && ("file" in config.logs) && ("customFileName" in config.logs.file)) {
                customFileName = config.logs.file.customFileName ? "-" + config.logs.file.customFileName : "";
            }
        }
        this._logger.info = function () {
            that._logger.log.apply(this._logger, [LevelLogs_js_1.LEVELSNAMES.INFO, ...arguments]);
        };
        this._logger.error = function () {
            that._logger.log.apply(this._logger, [LevelLogs_js_1.LEVELSNAMES.ERROR, ...arguments]);
        };
        this._logger.debug = function () {
            that._logger.log.apply(that._logger, [LevelLogs_js_1.LEVELSNAMES.DEBUG, ...arguments]);
        };
        this._logger.warn = function () {
            that._logger.log.apply(that._logger, [LevelLogs_js_1.LEVELSNAMES.WARN, ...arguments]);
        };
        this._logger.encrypt = function (str) {
            if (enableEncryptedLogs == true) {
                return cryptr.encrypt(str);
            }
            else {
                return ("");
            }
        };
        this._logger.decrypt = function (str) {
            return cryptr.decrypt(str);
        };
        this._logger.stripStringForLogs = function (value) {
            let result = "";
            if (self.logLevel !== LevelLogs_js_1.LEVELSNAMES.INFO) {
                result = value;
            }
            else {
                if (!value) {
                    result = value;
                }
                else {
                    value += "";
                    result = value.charAt(0) + value.replace(/[^\s](?=.{1,}$)/g, "*")?.substr(1);
                }
            }
            return result;
        };
        this.hideId = function (url) {
            return url.replace(/[\/="'][a-f\d]{24}[\/\?&"']?/ig, (x) => {
                let ret = x.toUpperCase();
                if (ret.length > 8) {
                    ret = ret.substring(0, 4) + "..." + ret.substring(ret.length - 4, ret.length);
                }
                return ret;
            });
        };
        this.hideUuid = function (url) {
            return url.replace(/[a-f0-9]{8}[a-f0-9]{4}4[a-f0-9]{3}[89aAbB][a-f0-9]{3}[a-f0-9]{12}[(@|c%40|\'|\")]/ig, (x) => {
                let ret = x.toUpperCase();
                if (ret.length > 8) {
                    ret = ret.substring(0, 4) + "..." + ret.substring(ret.length - 4, ret.length);
                }
                return ret;
            });
        };
        this.emit = function (level, info) {
            let event = LevelLogs_js_1.LEVELSNAMES.DEBUG;
            if (this.logEventEmitter && enableEventsLogs) {
                let msg = new Date().toISOString() + " - " + level + ": " + (info ? info.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '') : "");
                this._logEventEmitter.emit(event, msg);
            }
        };
        this._logger.stop = function () {
            return that._winston.end();
        };
        /*  this._logger.log = function (options : {"callerObj" : any, "level" : LEVELSNAMES, isApi : boolean} | LEVELSNAMES) {
              try {
                  const args = [...arguments];
                  console.log(new Date().toISOString() + args?.toString());
  
                  return (-1);
              } catch (err) {
              }
          } // */
        this._logger.log = function (options) {
            try {
                let levelOfLog;
                // Level of the SDK logs.
                let levelOfSdk = self.logLevel;
                let levelOfSdkValue = LevelLogs_js_1.LEVELS[self.logLevel];
                let levelLimit = LevelLogs_js_1.LEVELS.error;
                let isApi = false;
                let showAreaApi = false;
                if (typeof options === "object") {
                    let callerObj = options?.callerObj;
                    let callerAreaName = "unknown";
                    if (callerObj && (typeof callerObj.getAccessorName) === "function") {
                        callerAreaName = callerObj.getAccessorName();
                    }
                    // Current log's config.
                    let paramsOfAreaLogs = self._areasLogs ? self._areasLogs[callerAreaName] : { level: levelOfSdk };
                    levelOfLog = options?.level ? options.level : LevelLogs_js_1.LEVELSNAMES.INFO;
                    isApi = options?.isApi;
                    //showAreaApi = paramsOfAreaLogs.api;
                    showAreaApi = (0, Utils_js_1.isDefined)(paramsOfAreaLogs.api) ? paramsOfAreaLogs.api : true;
                    // Level of the current log.
                    //let levelOfLog = options?.level;
                    // let levelOfLogNumber = winston.config.syslog.levels[levelOfLog];
                    // let levelOfLogNumber = self.levels[levelOfLog];
                    // Level of the aera in the SDK config options.
                    let levelOfArea = "" + paramsOfAreaLogs?.level;
                    levelLimit = LevelLogs_js_1.LEVELS[levelOfArea];
                    //levelLimit = levelOfArea?LEVELS[levelOfArea]:levelOfSdkValue;
                    // console.log("paramOfClassLogs", paramsOfClassLogs);
                    //let levelOfAreaNumber = self.levels[paramsOfClassLogs?.level];
                    //let levelOfSdkNumber = self.levels[levelOfLog];
                    //console.log("callerName : ", callerName, ", level : ", level, ", levelOfLogNumber : ", levelOfLogNumber, ", levelOfAreaNumber : ", levelOfAreaNumber, ", levelOfSdkNumber : ", levelOfSdkNumber);
                    /*
                    if (levelOfAreaNumber > levelOfSdkNumber ) {
                        if (levelOfLogNumber > levelOfSdkNumber && levelOfLogNumber < levelOfSdkNumber) {
                            level=levelOfSdkNumber;
                        }
                    } // */
                    // Force to not log the entry if the sdk and the entry are configured to log at "debug" and the aera override at "info".
                    /*
                    if ((levelOfLog === "debug" || levelOfLog === "internal") && levelOfArea === "info" && levelOfSdk === "debug") {
                        return;
                    }
                    // Force to log the entry if the sdk is configured to "info" and the entry and area are configured to log at "debug". Override entry to "info".
                    if ((levelOfLog === "debug" || levelOfLog === "internal") && levelOfArea === "debug" && levelOfSdk === "info") {
                        level = "info";
                    }
                    // */
                    //console.log("callerName : ", callerName, ", levelOfLog : ", levelOfLog, ", levelOfArea : ", levelOfArea, ", levelOfSdk : ", levelOfSdk);
                }
                else {
                    levelOfLog = options;
                    levelLimit = levelOfSdkValue;
                }
                if (!levelOfLog) {
                    console.log("!!! undefined levelOfLog : ", levelOfLog, ", arguments : ", ...arguments);
                }
                let levelOfLogValue = LevelLogs_js_1.LEVELS[levelOfLog];
                //console.log("levelOfLog : ", levelOfLog, ", levelOfLogValue : ", levelOfLogValue, ", levelLimit : ", levelLimit);
                if (levelOfLogValue > levelLimit || (isApi && !showAreaApi)) {
                    //console.log("levelOfLogValue : ", levelOfLogValue, "is supperior to levelLimit : ", levelLimit, " so ignore log.");
                    return;
                }
                if (levelOfLog === "internal" || levelOfLog === "internalerror") {
                    if (logInternals === true) {
                        //level = (level === "internal") ? "debug" : "error";
                        let datatolog = that.colors.italic(that.colors.red("FORBIDDEN TO LOG THIS DATA IN PROD ENV !!! Sorry."));
                        // console.log(datatolog);
                        /*
                        if (levelOfLog === "internal") {
                            levelOfLog = LevelLogs_js_1.LEVELSNAMES.DEBUG;
                            datatolog = that.colors.italic(that.colors.red("PROD HIDDEN : ")) + that.argumentsToString(arguments);
                            that._winston.log.apply(that._winston, [levelOfLog, that._logger.customLabel + datatolog]);
                            that.emit(levelOfLog, that._logger.customLabel + datatolog);
                        }
                        else if (levelOfLog === "internalerror") {
                            levelOfLog = LevelLogs_js_1.LEVELSNAMES.ERROR;
                            datatolog = that.colors.italic(that.colors.red("PROD HIDDEN : ")) + that.argumentsToStringFull(arguments);
                            that._winston.log.apply(that._winston, [levelOfLog, that._logger.customLabel + datatolog]);
                            that.emit(levelOfLog, that._logger.customLabel + datatolog);
                        }
                        /* */
                        // */
                        /*
                        if ( level === "internal") {
                            level = "debug";
                            that._winston.log.apply(that._winston, [level, that._logger.customLabel + that.hideId(that.hideUuid(that.argumentsToString(arguments)))]);
                            that.emit(level, that._logger.customLabel + that.hideId(that.hideUuid(that.argumentsToString(arguments))));
                        }
                        else
                            if (level === "internalerror") {
                                level = "error";
                                that._winston.log.apply(that._winston, [level, that._logger.customLabel + that.hideId(that.hideUuid(that.argumentsToString(arguments)))]);
                                that.emit(level, that._logger.customLabel + that.hideId(that.hideUuid(that.argumentsToString(arguments))));
                            }
                        // */
                    }
                }
                else {
                    let datatolog = that.argumentsToString(arguments);
                    if (logInternals) {
                        that._winston.log.apply(that._winston, [levelOfLog, that._logger.customLabel + datatolog]);
                        that.emit(levelOfLog, that._logger.customLabel + datatolog);
                    }
                    else {
                        that._winston.log.apply(that._winston, [levelOfLog, that._logger.customLabel + that.hideId(that.hideUuid(datatolog))]);
                        that.emit(levelOfLog, that._logger.customLabel + that.hideId(that.hideUuid(datatolog)));
                    }
                }
            }
            catch (err) {
                console.error("CATCH Error !!! while logging : " + err);
            }
        };
        if (enableConsoleLog && enableFileLog) {
            this._winston = winston.createLogger({
                levels: LevelLogs_js_1.LEVELS,
                format: winston.format.combine(
                /*
                winston.format.timestamp({
                    // 03/20/2025 10:00:11:846
                    format: 'MM/DD/YYYY HH:MM:SS:SSS'
                }),
                // */
                /* winston.format.label({
                    label: "MonLabel"
                }), // */
                winston.format.errors({ stack: true }), // <-- use errors format
                winston.format.colorize({ all: self.logColor }), 
                //winston.format.label({ label: 'right meow!' }),
                //winston.format.colorize({ all: false }),
                winston.format.simple(), winston.format.timestamp(), logFormat
                //winston.format.prettyPrint()
                ),
                transports: [
                    new (winston.transports.Console)({
                        level: LevelLogs_js_1.LEVELSNAMES.INTERNAL,
                    }),
                    new (DailyRotateFile)({
                        name: 'logs',
                        filename: `${logDir}/%DATE%-rainbowsdk${customFileName}.log`,
                        maxSize: maxSize,
                        zippedArchive: zippedArchive,
                        timestamp: tsFormat,
                        datePattern: "YYYY-MM-DD",
                        maxFiles: maxFiles,
                        prepend: true,
                        level: LevelLogs_js_1.LEVELSNAMES.INTERNAL
                        //level: self.logLevel
                    })
                ]
            });
            welcome();
            this._logger.log("info", LOG_ID + "(constructor) console and file logs enabled");
            this._logger.log("info", LOG_ID + "(constructor) logs store in directory", logDir);
        }
        else if (enableConsoleLog) {
            this._winston = winston.createLogger({
                levels: LevelLogs_js_1.LEVELS,
                format: winston.format.combine(winston.format.errors({ stack: true }), // <-- use errors format
                winston.format.colorize({ all: self.logColor }), winston.format.simple(), 
                //winston.format.label({ label: 'right meow!' }),
                winston.format.timestamp(), 
                /*winston.format.timestamp({
                    // 03/20/2025 10:00:11:846
                    format: 'MM/DD/YYYY HH:MM:SS:SSS'
                }), // */
                logFormat
                //winston.format.prettyPrint()
                ),
                transports: [
                    new (winston.transports.Console)({
                        level: LevelLogs_js_1.LEVELSNAMES.INTERNAL
                    })
                ]
            });
            //  this._winston.addColors(this._winston.config.syslog.colors, { "trace": this._winston.config.syslog.colors.debug, "xmpp": this._winston.config.syslog.colors.debug, "internal": this._winston.config.syslog.colors.debug, "internalerror": this._winston.config.syslog.colors.error})
            welcome();
            this._logger.log("info", LOG_ID + "(constructor) No file logs enabled");
        }
        else if (enableFileLog) {
            this._winston = winston.createLogger({
                levels: LevelLogs_js_1.LEVELS,
                format: winston.format.combine(winston.format.errors({ stack: true }), // <-- use errors format
                winston.format.colorize({ all: self.logColor }), 
                //winston.format.label({ label: 'right meow!' }),
                winston.format.timestamp(), 
                /* winston.format.timestamp({
                    // 03/20/2025 10:00:11:846
                    format: 'MM/DD/YYYY HH:MM:SS:SSS'
                }), // */
                logFormat
                //winston.format.prettyPrint()
                ),
                transports: [
                    new (DailyRotateFile)({
                        name: 'logs',
                        filename: `${logDir}/%DATE%-rainbowsdk${customFileName}.log`,
                        maxSize: maxSize,
                        zippedArchive: zippedArchive,
                        timestamp: tsFormat,
                        datePattern: "YYYY-MM-DD",
                        maxFiles: maxFiles,
                        prepend: true,
                        level: LevelLogs_js_1.LEVELSNAMES.INTERNAL
                    })
                ]
            });
            welcome();
            this._logger.log("info", LOG_ID + "(constructor) No console logs enabled");
            this._logger.log("info", LOG_ID + "(constructor) logs store in directory", logDir);
        }
        else {
            this._winston = winston.createLogger({
                transports: [],
                silent: true
            });
            // No logs :-)
        }
        /*
        let loggers = winston.loggers;

        for (const logguersKey in loggers) {
            console.log("logguer : ", logguersKey, " : ", loggers[logguersKey]);
        }
        // */
        if (that._winston.writable) {
            that._winston.on('error', () => { })
                .on('close', () => { })
                // flush isn't guaranteed to fire. Since files aren't flushed before 'finish' is fired,
                // wait 50ms before closing the logger.
                .on('finish', () => {
                setTimeout(() => {
                    that._winston.close();
                    //console.log("finish winston.");
                }, 50);
            });
            //.end();
        }
        else {
        }
        if (self._logger) {
            self._logger.colors = self.colors;
            self._logger.logLevel = self.logLevel;
        }
    }
    get log() {
        return this._logger;
    }
    argumentsToStringReduced(v, delemiter = " ") {
        // convert arguments object to real array
        let args = Array.prototype.slice.call(v, 1);
        let options = {
            showHidden: false,
            depth: 3,
            colors: this.logColor,
            maxArrayLength: 3
        };
        for (let k in args) {
            /* if (isPlainObject(args[k])) {
                 args[k] = util.inspect(args[k], options);
             }// */
            //            if (typeof args[k] === "object"){
            if ((0, Utils_js_1.isInstanceOfClass)(args[k])) {
                // args[k] = JSON.stringify(args[k]);
                args[k] = util.inspect(args[k], options);
            }
            else if ((0, Utils_js_1.isJsonObject)(args[k])) {
                if ((0, Utils_js_1.isPlainObject)(args[k])) {
                    args[k] = util.inspect(args[k], options);
                }
                else {
                    args[k] = JSON.stringify(args[k]);
                }
            }
            // */
        }
        //let str =  Array.prototype.join.call(args, delemiter);
        let str = args.join(delemiter);
        return str;
    }
    argumentsToStringFull(v, delemiter = " ") {
        // convert arguments object to real array
        let args = Array.prototype.slice.call(v, 1);
        let options = {
            showHidden: false,
            depth: null,
            colors: this.logColor
            //maxArrayLength : 5
        };
        for (let k in args) {
            if ((0, Utils_js_1.isPlainObject)(args[k])) {
                args[k] = util.inspect(args[k], options);
            }
            /*
                   //if (typeof args[k] === "object"){
                   if (isInstanceOfClass(args[k])){
                       // args[k] = JSON.stringify(args[k]);
                       args[k] = util.inspect(args[k], false, null, this.logColor);
                   } else if (isJsonObject(args[k])){
                       if (isPlainObject(args[k])) {
                           args[k] = util.inspect(args[k], false, null, this.logColor);
                       } else {
                           args[k] = JSON.stringify(args[k]);
                       }
                   }
                   // */
        } // */
        let str = args.join(delemiter);
        return str;
    }
}
exports.Logger = Logger;
module.exports.Logger = Logger;
//# sourceMappingURL=Logger.js.map