import * as path from 'path' ; interface Callsite { getLineNumber ( ) : number ; getFileName ( ) : string ; } function getCallsite ( ) { const originalPrepareStackTrace = Error . prepareStackTrace ; Error . prepareStackTrace = ( _ , stack ) => { return stack ; } ; const error = new Error ( ) ; Error . captureStackTrace ( error , getCallsite ) ; const stack = error . stack as any as Callsite [ ] ; Error . prepareStackTrace = originalPrepareStackTrace ; return stack [ 1 ] ; } type LevelPrefix = 'E' | 'W' | 'I' | 'D' ; function makeLogMessage ( level , callsite , message ) { const timeStr = new Date ( ) . toISOString ( ) ; return `${ level }${ timeStr } ${ process . pid } ${ path . basename ( callsite . getFileName ( ) || __filename ) }:${ callsite . getLineNumber ( ) }] ${ message }` ; } export function error ( message ) { console . error ( makeLogMessage ( 'E' , getCallsite ( ) , message ) ) ; } export function warn ( message ) { console . warn ( makeLogMessage ( 'W' , getCallsite ( ) , message ) ) ; } export function info ( message ) { console . info ( makeLogMessage ( 'I' , getCallsite ( ) , message ) ) ; } export function debug ( message ) { console . debug ( makeLogMessage ( 'D' , getCallsite ( ) , message ) ) ; }