"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loggerRegistry = void 0;
/**
 * Singleton registry for the logging adapter.
 *
 * Follows the same pattern as telemetryRegistry and eventRegistry:
 * - register(adapter) — set the logging adapter
 * - clear()           — reset (for tests)
 *
 * When no adapter is registered, all methods fall back to console.*.
 */
const LOG_LEVELS = { error: 0, warn: 1, info: 2, debug: 3 };
function shouldLog(level) {
    const threshold = LOG_LEVELS[process.env.LOG_LEVEL || 'debug'] ?? 3;
    return (LOG_LEVELS[level] ?? 3) <= threshold;
}
class LTLoggerRegistry {
    constructor() {
        this.adapter = null;
    }
    /**
     * Register a logging adapter. Replaces any previously registered adapter.
     */
    register(adapter) {
        this.adapter = adapter;
    }
    /**
     * Remove the adapter and reset state. Used in tests.
     */
    clear() {
        this.adapter = null;
    }
    /**
     * Check if an adapter is registered.
     */
    get hasAdapter() {
        return this.adapter !== null;
    }
    info(msg, context) {
        if (this.adapter) {
            this.adapter.info(msg, context);
        }
        else if (shouldLog('info')) {
            console.log(msg);
        }
    }
    warn(msg, context) {
        if (this.adapter) {
            this.adapter.warn(msg, context);
        }
        else if (shouldLog('warn')) {
            console.warn(msg);
        }
    }
    error(msg, context) {
        if (this.adapter) {
            this.adapter.error(msg, context);
        }
        else if (shouldLog('error')) {
            console.error(msg);
        }
    }
    debug(msg, context) {
        if (this.adapter) {
            this.adapter.debug(msg, context);
        }
        else if (shouldLog('debug')) {
            console.debug(msg);
        }
    }
}
/** Singleton logger registry */
exports.loggerRegistry = new LTLoggerRegistry();
