import { randomBytes } from 'crypto' ; const signature = randomBytes ( 16 ) . toString ( 'base64' ) ; interface ILogger { debug ( ... data ) : void ; warn ( ... data ) : void ; error ( ... data ) : void ; } class Logger implements ILogger { debug ( ... data ) { process . env [ 'FIDO2_CLIENT_DEBUG' ] === 'TRUE' ? console . log . apply ( console , [ `[${ new Date ( ) . toLocaleString ( ) }]` , `[${ ( new Error ( signature ) ) . stack ?. split ( `Error: ${ signature }\n` ) [ 1 ] . split ( '\n' ) [ 1 ] . trim ( ) . substring ( 3 ) . replace ( /\s\(/ , ' ' ) . replace ( /\)/ , '' ) }]` , '[LOG]' , ... data ] ) : undefined ; } error ( ... data ) { console . log . apply ( console , [ `[${ new Date ( ) . toLocaleString ( ) }]` , `[${ ( new Error ( signature ) ) . stack ?. split ( `Error: ${ signature }\n` ) [ 1 ] . split ( '\n' ) [ 1 ] . trim ( ) . substring ( 3 ) . replace ( /\s\(/ , ' ' ) . replace ( /\)/ , '' ) }]` , '[ERR]' , ... data ] ) ; } warn ( ... data ) { console . log . apply ( console , [ `[${ new Date ( ) . toLocaleString ( ) }]` , `[${ ( new Error ( signature ) ) . stack ?. split ( `Error: ${ signature }\n` ) [ 1 ] . split ( '\n' ) [ 1 ] . trim ( ) . substring ( 3 ) . replace ( /\s\(/ , ' ' ) . replace ( /\)/ , '' ) }]` , '[WAR]' , ... data ] ) ; } } export const logger = new Logger ( ) ;