/** Log levels. */ export enum LogLevel { DEBUG , LOG , INFO , WARN , ERROR , OFF } /** Interface definition for the logger. */ export interface ILogger { debug : typeof console . debug ; log : typeof console . log ; info : typeof console . info ; warn : typeof console . warn ; error : typeof console . error ; } /** The logger class. */ export class Logger implements ILogger { private static readonly LOG_LEVELS : [ 'debug' , 'log' , 'info' , 'warn' , 'error' ] = [ 'debug' , 'log' , 'info' , 'warn' , 'error' ] ; param logger param level public constructor ( private readonly logger = console , private level = LogLevel . INFO ) { } param level public setLogLevel ( level ) { this . level = level ; } returns public isDebugEnabled ( ) { return this . level <= LogLevel . DEBUG ; } param message param optionalParams public debug ( message ? , ... optionalParams ) { this . message ( LogLevel . DEBUG , message , ... optionalParams ) ; } param message param optionalParams public log ( message ? , ... optionalParams ) { this . message ( LogLevel . LOG , message , ... optionalParams ) ; } param message param optionalParams public info ( message ? , ... optionalParams ) { this . message ( LogLevel . INFO , message , ... optionalParams ) ; } param message param optionalParams public warn ( message ? , ... optionalParams ) { this . message ( LogLevel . WARN , message , ... optionalParams ) ; } param message param optionalParams public error ( message ? , ... optionalParams ) { this . message ( LogLevel . ERROR , message , ... optionalParams ) ; } private message ( level , message ? , ... optionalParams ) { if ( this . level !== LogLevel . OFF && this . level <= level ) { const logLevel = Logger . LOG_LEVELS [ level as number ] ; if ( logLevel ) { this . logger [ logLevel ] ( message , ... optionalParams ) ; } } } } param logger returns export function createLogger ( logger = console ) { return new Logger ( logger ) ; }