import util from 'node:util';

const TRACE_ENABLED = false;
const LOG_ENABLED = process.env.BOX_ENV !== 'test' || !!process.env.LOG;

function output(namespace, args) {
    const ts = new Date().toISOString();
    process.stdout.write(`${ts} ${namespace}: ${util.format(...args)}\n`);
}

export default function logger(namespace) {
    return {
        log: LOG_ENABLED ? (...args) => output(namespace, args) : () => {},
        trace: TRACE_ENABLED ? (...args) => output(namespace, args) : () => {},
    };
}
