import ILogger from './ILogger' ; type AnyDictionary = { [ s ] : any ; } ; const stringifyMessageProperties = ( message , level ) : string => { return JSON . stringify ( Object . getOwnPropertyNames ( message ) . reduce ( ( plainObject , key ) => { plainObject [ key ] = message [ key ] ; return plainObject ; } , { level } as AnyDictionary ) ) ; } ; const stringifyNonStackedErrorMessage = ( message , level ) : string => { if ( message == null ) { return JSON . stringify ( { level } ) ; } if ( typeof message === 'string' ) { try { const parsedMessage = JSON . parse ( message ) as AnyDictionary | any [ ] ; return JSON . stringify ( { ... parsedMessage , ... { level } } ) ; } catch ( _ ) { return `level: ${ level }, ${ message }` ; } } return stringifyMessageProperties ( message , level ) ; } ; see https param { any } message param { keyof ILogger } level return export default ( message , level ) : string => { return message != null && message . stack ? stringifyMessageProperties ( message , level ) : stringifyNonStackedErrorMessage ( message , level ) ; } ;