namespace Utils { export const enum LogSeverity { Default , Info , Success , Debug , Error , Warning } interface LogOptions { [ severity ] : boolean ; } let logOptions = { } ; logOptions [ LogSeverity . Default ] = true ; logOptions [ LogSeverity . Info ] = true ; logOptions [ LogSeverity . Success ] = true ; logOptions [ LogSeverity . Debug ] = false ; logOptions [ LogSeverity . Error ] = true ; logOptions [ LogSeverity . Warning ] = true ; interface LogMethods { [ severity ] : ( message ? : string , ... optionalParams : any [ ] ) => void ; } let logMethods = { } ; if ( console ) { logMethods [ LogSeverity . Default ] = ( console . log ) ? console . log . bind ( console ) : undefined ; logMethods [ LogSeverity . Info ] = ( console . info ) ? console . info . bind ( console ) : logMethods [ LogSeverity . Default ] ; logMethods [ LogSeverity . Success ] = logMethods [ LogSeverity . Info ] ; logMethods [ LogSeverity . Debug ] = logMethods [ LogSeverity . Info ] ; logMethods [ LogSeverity . Warning ] = ( console . warn ) ? console . warn . bind ( console ) : logMethods [ LogSeverity . Default ] ; logMethods [ LogSeverity . Error ] = ( console . error ) ? console . error . bind ( console ) : logMethods [ LogSeverity . Warning ] ; } export function logEnabled ( severity ) { return ( ( logOptions [ severity ] ) && ( logMethods [ severity ] ) ) ? true : false ; } export function log ( severity , message ? , ... optionalParams ) { if ( ( logOptions [ severity ] ) && ( logMethods [ severity ] ) ) logMethods [ severity ] ( message , ... optionalParams ) ; } }