"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 TimeStamp = __importStar(require("../utils/TimeStamp"));
const LogLevel_1 = require("./LogLevel");
/**
 * Defines a basic output-Format
 *
 * @param minMessageLength Defines the minimum length of the message
 * @param maxNameLength Defines the maximal output length of logger name
 */
// prettier-ignore
exports.defaultFormatter = (minMessageLength = 50, maxNameLength = 30) => {
    return {
        format: (level, timestamp, loggerName, message) => {
            const formattedTimeStamp = TimeStamp.toTime(timestamp);
            return `${formattedTimeStamp} [${LogLevel_1.LogLevel[level]}] ` +
                `${exports.padMessage(message, minMessageLength)}` +
                ` | ${exports.truncateLoggerName(loggerName, maxNameLength)}`;
        },
        optional: toJson,
    };
};
exports.jsonFormatter = {
    format: (level, timestamp, loggerName, message) => {
        return JSON.stringify({
            level,
            timestamp: TimeStamp.toTime(timestamp),
            name: loggerName,
            message,
        });
    },
    optional: toJson,
};
exports.padMessage = (message, length) => {
    // if (message.length > length) {
    //     return `${message.substr(0, length - 3)}...`;
    // }
    return message.padEnd(length);
};
exports.truncateLoggerName = (loggerName, length) => {
    const reverse = (value) => value
        .split('')
        .reverse()
        .join('');
    if (loggerName.length > length) {
        let temp = reverse(loggerName);
        temp = temp.substr(0, length + 3);
        return `...${reverse(temp)}`;
    }
    return loggerName.padEnd(length);
};
function toJson(obj, spaces = 4) {
    if (obj) {
        return `\n${JSON.stringify(JSON.parse(JSON.stringify(obj)), undefined, spaces)}`;
    }
    return obj;
}
exports.toJson = toJson;
//# sourceMappingURL=Formatter.js.map