import { EventEmitter } from 'events' ; import * as fs from 'fs' ; type AttachLoggerResult = { /**
     * Detaches the logger from the emitter and closes the write stream to the
     * log file
     */ stop ( ) : void ; } ; param filePath param emitter function attachLogger < Emitter extends EventEmitter > ( filePath , emitter ) { const writeStream = fs . createWriteStream ( filePath , { flags : 'a' , } ) ; function onData ( data ) { writeStream . write ( data . toString ( ) ) ; } function onError ( data ) { writeStream . write ( data . toString ( ) ) ; } emitter . on ( 'data' , onData ) ; emitter . on ( 'error' , onError ) ; return { stop ( ) { emitter . off ( 'data' , onData ) ; emitter . off ( 'error' , onError ) ; writeStream . close ( ) ; } , } ; } export { attachLogger } ; export type { AttachLoggerResult } ;