const LOG_LEVELS = {
    debug: 0,
    info: 1,
    warn: 2,
    error: 3,
    // `silent` sits above every emit level so the `level < minLevelNum`
    // guard in `log()` always short-circuits when configured. Used by
    // test harnesses to suppress unmocked `getRootLogger()` stderr
    // writes; see packages/sdk/src/test-setup.ts.
    silent: 4,
};
function createLoggerImpl(name, minLevel, parentContext) {
    const minLevelNum = LOG_LEVELS[minLevel];
    function log(level, message, data) {
        if (LOG_LEVELS[level] < minLevelNum)
            return;
        const timestamp = new Date().toISOString();
        const prefix = `[${timestamp}] [${level.toUpperCase()}] [${name}]`;
        const merged = { ...parentContext, ...data };
        const hasContext = Object.keys(merged).length > 0;
        if (hasContext) {
            process.stderr.write(`${prefix} ${message} ${JSON.stringify(merged)}\n`);
        }
        else {
            process.stderr.write(`${prefix} ${message}\n`);
        }
    }
    function child(context) {
        return createLoggerImpl(context.component ? String(context.component) : name, minLevel, {
            ...parentContext,
            ...context,
        });
    }
    return {
        debug: (msg, data) => log('debug', msg, data),
        info: (msg, data) => log('info', msg, data),
        warn: (msg, data) => log('warn', msg, data),
        error: (msg, data) => log('error', msg, data),
        child,
    };
}
let _rootLogger = null;
export function getRootLogger() {
    if (!_rootLogger) {
        _rootLogger = createLoggerImpl('namzu', 'info', {});
    }
    return _rootLogger;
}
export function configureLogger(options) {
    _rootLogger = createLoggerImpl('namzu', options.level ?? 'info', {});
}
//# sourceMappingURL=logger.js.map