import { LogLevelType } from '../constants' ; import { MessageBuilder } from './MessageBuilder' ; const NOOP = ( ) => ( { } ) ; export class MessagePrinter { constructor ( private readonly messageBuilder ) { } public print ( level , args ) { this . printPreparedMessage ( this . messageBuilder . build ( level , args ) + '\n' ) ; } private printPreparedMessage ( message ) { try { if ( process . stdout . listenerCount ( 'error' ) === 0 ) { process . stdout . once ( 'error' , NOOP ) ; } process . stdout . write ( message , NOOP ) ; } catch ( err ) { } finally { process . stdout . removeListener ( 'error' , NOOP ) ; } } }