import { Console } from "console" ; import { createWriteStream } from "fs" ; export interface TtyLoggerOptions { fallbackOnError ? : "none" | "console" ; } const defaultOptions = { fallbackOnError : "console" , } ; const nullLog = ( ) => { } ; const consoleLog = console . log . bind ( console ) ; export function createTtyLogger ( options = { } ) { const opts = { ... defaultOptions , ... options } ; const tty = createWriteStream ( "/dev/tty" ) ; let log ; const logger = new Console ( tty , tty ) ; log = logger . log . bind ( logger ) ; tty . on ( "error" , ( ) => log = opts . fallbackOnError === "console" ? consoleLog : nullLog ) ; return function ttyLog ( ... args ) { log ( ... args ) ; } ; }