/**
 * Structured Logger for UAP
 *
 * Replaces bare console.log/warn/error calls in runtime modules with
 * a configurable logger that respects verbosity levels.
 *
 * Levels: silent < error < warn < info < debug
 *
 * Set via:
 * - UAP_LOG_LEVEL env var (e.g., UAP_LOG_LEVEL=debug)
 * - Programmatic: setLogLevel('debug')
 */
const LEVEL_ORDER = {
    silent: 0,
    error: 1,
    warn: 2,
    info: 3,
    debug: 4,
};
let currentLevel = process.env.UAP_LOG_LEVEL || 'warn';
export function setLogLevel(level) {
    currentLevel = level;
}
export function getLogLevel() {
    return currentLevel;
}
function shouldLog(level) {
    return LEVEL_ORDER[level] <= LEVEL_ORDER[currentLevel];
}
function formatPrefix(_level, module) {
    const tag = module ? `[${module}]` : '[uap]';
    return `${tag}`;
}
/**
 * Create a module-scoped logger.
 *
 * @param module - Module name for log prefix (e.g., 'mcp-router', 'memory')
 */
export function createLogger(module) {
    return {
        error(message, ...args) {
            if (shouldLog('error')) {
                console.error(formatPrefix('error', module), message, ...args);
            }
        },
        warn(message, ...args) {
            if (shouldLog('warn')) {
                console.warn(formatPrefix('warn', module), message, ...args);
            }
        },
        info(message, ...args) {
            if (shouldLog('info')) {
                console.log(formatPrefix('info', module), message, ...args);
            }
        },
        debug(message, ...args) {
            if (shouldLog('debug')) {
                console.log(formatPrefix('debug', module), message, ...args);
            }
        },
    };
}
/**
 * Global logger instance for modules that don't need a specific prefix.
 */
export const logger = createLogger('uap');
//# sourceMappingURL=logger.js.map