"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
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("../../utils/environment/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/test-${process.pid}.log`,
        }),
        new winston.transports.File({
            filename: './logs/test-latest.log',
        }),
    ],
});
logger.debug(['melon:protocol:logger', 'init', ...process.argv].join(' '));
const testLogger = R.curryN(3, (namespace, level, ...msgs) => {
    const message = [
        `${namespace}:`,
        ...msgs.map(msg => JSON.stringify(msg, null, 2)),
    ].join(' ');
    require('debug')(namespace)(level, ...msgs);
    logger.log(level, message);
});
exports.testLogger = testLogger;
// Helper function to await that all logs are written to the fil
const allLogsWritten = () => __awaiter(this, void 0, void 0, function* () {
    return new Promise(resolve => {
        logger.on('finish', resolve);
        setTimeout(resolve, 1000);
    });
});
exports.allLogsWritten = allLogsWritten;
