import { redactForLogging, redactValue } from "./redaction.js";
const LEVELS = {
    debug: 10,
    info: 20,
    warn: 30,
    error: 40,
};
export function createLogger(level) {
    const threshold = LEVELS[level];
    function write(entryLevel, message, metadata = {}) {
        if (LEVELS[entryLevel] < threshold) {
            return;
        }
        const entry = {
            ts: new Date().toISOString(),
            level: entryLevel,
            message,
            ...metadata,
        };
        const output = redactValue(JSON.stringify(redactForLogging(entry)));
        if (entryLevel === "error") {
            console.error(output);
        }
        else if (entryLevel === "warn") {
            console.warn(output);
        }
        else {
            console.log(output);
        }
    }
    return {
        debug: (message, metadata) => write("debug", message, metadata),
        info: (message, metadata) => write("info", message, metadata),
        warn: (message, metadata) => write("warn", message, metadata),
        error: (message, metadata) => write("error", message, metadata),
    };
}
