import { inspect } from '@devvit/shared-types/inspect.js';
import { makeBufferedLogFunction } from './bufferedLog.js';
import { LogType } from './LogType.js';
const inspectOrPrint = (val) => (typeof val === 'string' ? val : inspect(val));
const formatLogString = (vals) => vals.map(inspectOrPrint).join(' ');
let logFunction;
if (typeof __builtin_log === 'function') {
    logFunction = __builtin_log;
}
else if (typeof __builtin_log_buffer === 'object' &&
    typeof __builtin_log_buffer_flush === 'function') {
    logFunction = makeBufferedLogFunction(__builtin_log_buffer, __builtin_log_buffer_flush);
}
const logMethod = (type) => (...vals) => {
    logFunction(type, formatLogString(vals));
};
const console = {
    log: logMethod(LogType.Log),
    info: logMethod(LogType.Info),
    warn: logMethod(LogType.Warn),
    error: logMethod(LogType.Error),
    debug: logMethod(LogType.Debug),
    dir(obj, opts) {
        logFunction(LogType.Debug, inspect(obj, opts));
    },
};
if (globalThis.console === undefined) {
    globalThis.console = console;
}
