01d0c738bc
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
17 lines
510 B
JavaScript
17 lines
510 B
JavaScript
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) : () => {},
|
|
};
|
|
}
|