"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const R = __importStar(require("ramda"));
const winston = __importStar(require("winston"));
const Environment_1 = require("./Environment");
const { combine, timestamp, printf } = winston.format;
const myFormat = printf(info => {
    return `${info.timestamp} ${info.level} ${info.message}`;
});
const logger = winston.createLogger({
    format: combine(timestamp(), myFormat),
    level: Environment_1.LogLevels.DEBUG,
    transports: [
        new winston.transports.File({
            filename: `./logs/cli-${process.pid}.log`,
        }),
        new winston.transports.File({
            filename: './logs/cli-latest.log',
        }),
        new winston.transports.Console({
            level: Environment_1.LogLevels.INFO,
        }),
    ],
});
logger.debug(['melon:protocol:logger', 'init cliLogger', ...process.argv].join(' '));
const cliLogger = R.curryN(3, (namespace, level, ...msgs) => {
    const message = [
        `${namespace}:`,
        ...msgs.map(msg => JSON.stringify(msg, null, 2)),
    ].join(' ');
    logger.log(level, message);
    require('debug')(namespace)(level, ...msgs);
});
exports.cliLogger = cliLogger;
