"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makePrinter = void 0;
const log_level_1 = require("./log-level");
function makePrinter({ handler, level = log_level_1.LogLevel.silent, format }) {
    var _a;
    const formatter = (_a = format === null || format === void 0 ? void 0 : format.formatter) !== null && _a !== void 0 ? _a : ((chunks, options) => ({ chunks, options, isRaw: true }));
    return { debug, log, info: log, warn, error, fatal, verbose: log };
    function debug(...messages) {
        if (level < log_level_1.LogLevel.debug)
            return;
        const options = { ...format, level: 'debug' };
        handler.log(formatter(messages, options));
    }
    function log(...messages) {
        if (level < log_level_1.LogLevel.info)
            return;
        const options = { ...format, level: 'info' };
        handler.log(formatter(messages, options));
    }
    function warn(...messages) {
        if (level < log_level_1.LogLevel.warn)
            return;
        const options = { ...format, level: 'warn' };
        if (handler.warn)
            handler.warn(formatter(messages, options));
        else
            handler.log(formatter(messages, options));
    }
    function error(...messages) {
        if (level < log_level_1.LogLevel.error)
            return;
        const options = { ...format, level: 'error' };
        if (handler.error)
            handler.error(formatter(messages, options));
        else
            handler.log(formatter(messages, options));
    }
    function fatal(...messages) {
        if (level < log_level_1.LogLevel.fatal)
            return;
        const options = { ...format, level: 'fatal' };
        if (handler.fatal)
            handler.fatal(formatter(messages, options));
        else if (handler.error)
            handler.error(formatter(messages, options));
        else
            handler.log(formatter(messages, options));
    }
}
exports.makePrinter = makePrinter;
