@jsvision/core / createLogger
Function: createLogger()
createLogger(
options?):Logger
Defined in: safety/logger.ts:249
Create a screen-safe logger.
Enablement. Off unless you pass enabled: true, set JSVISION_DEBUG=1, or choose sink: 'ring'. A disabled logger is a pure no-op (every method returns without writing and entries() is empty), so a normal run writes nothing.
Sink selection (sink: 'auto', the default): a file if a path is set (options.path or the JSVISION_LOG env var); else stderr when it is a different device from the screen; else the in-memory ring buffer.
Screen safety. Construction throws LoggerConfigError if the chosen sink would resolve to the terminal's own output stream, so a misconfigured logger can never corrupt your rendered UI.
Parameters
options?
LoggerOptions = {}
Optional configuration; env vars supply the defaults.
Returns
A Logger. It is a no-op when not enabled.
Throws
LoggerConfigError when the resolved sink targets the terminal's output stream.
Example
import { createLogger } from '@jsvision/core';
// Enable via env (JSVISION_DEBUG=1) and log to a file (JSVISION_LOG=/tmp/app.log):
const log = createLogger();
log.info('host', 'started', { cols: 120, rows: 40 });
// Or capture in memory for a diagnostics dump (always enabled):
const ring = createLogger({ sink: 'ring' });
ring.debug('input', 'key pressed');
console.error(ring.entries());
ring.close();