import * as util from 'util' ; import * as types from './types' ; /**
 * This class implements a console logger.
 */ export class ConsoleLogger implements types . Logger { static LEVELS = [ 'silent' , 'error' , 'warn' , 'info' , 'debug' ] ; public level : string ; private namespace : string = 'core' ; param options constructor ( options ? ) { let opt = { } ; if ( typeof options === 'number' ) { if ( options < 0 ) { options = 0 ; } else if ( options > ConsoleLogger . LEVELS . length ) { options = ConsoleLogger . LEVELS . length - 1 ; } opt = { level : ConsoleLogger . LEVELS [ options ] } ; } else if ( typeof options === 'string' ) { opt = { level : options } ; } else { opt = options || { } ; } this . level = opt . level || 'error' ; if ( typeof options === 'object' && options . namespace ) { this . namespace = options . namespace ; } } param message param args error ( message , ... args ) { if ( ConsoleLogger . LEVELS . indexOf ( this . level ) < 1 ) return ; console . log ( `${ new Date ( ) . toISOString ( ) } - ${ this . namespace } - ERROR - ${ util . format ( message , ... args ) }` ) ; } param message param args warn ( message , ... args ) { if ( ConsoleLogger . LEVELS . indexOf ( this . level ) < 2 ) return ; console . log ( `${ new Date ( ) . toISOString ( ) } - ${ this . namespace } - WARN - ${ util . format ( message , ... args ) }` ) ; } param message param args info ( message , ... args ) { if ( ConsoleLogger . LEVELS . indexOf ( this . level ) < 3 ) return ; console . log ( `${ new Date ( ) . toISOString ( ) } - ${ this . namespace } - INFO - ${ util . format ( message , ... args ) }` ) ; } param message param args debug ( message , ... args ) { if ( ConsoleLogger . LEVELS . indexOf ( this . level ) < 4 ) return ; console . log ( `${ new Date ( ) . toISOString ( ) } - ${ this . namespace } - DEBUG - ${ util . format ( message , ... args ) }` ) ; } } param options const logger = ( options ? ) : types . Logger => { return new ConsoleLogger ( options ) ; } ; export { logger } ;