import * as JSON from "circular-json" ; export enum LogLevel { none = 0 , info = 1 , warn = 2 , debug = 4 , error = 8 , all = 15 } export interface ILogger { param message debug ( message ) : void ; param message info ( message ) : void ; param message warn ( message ) : void ; param message error ( message ) : void ; } class ConsoleLogger implements ILogger { public debug ( message ) { if ( LoggingService . logLevel & LogLevel . debug ) { console . log ( `${ LoggingService . moduleName } (debug): ${ message }` ) ; } } public info ( message ) { if ( LoggingService . logLevel & LogLevel . info ) { console . log ( `${ LoggingService . moduleName } (info): ${ message }` ) ; } } public warn ( message ) { if ( LoggingService . logLevel & LogLevel . warn ) { console . log ( `${ LoggingService . moduleName } (warn): ${ message }` ) ; } } public error ( message ) { if ( LoggingService . logLevel & LogLevel . error ) { console . log ( `${ LoggingService . moduleName } (error): ${ message }` ) ; } } } /**
 * Provides logging support, logging by default to the JavaScript console.  You can provide
 * alternate or additional loggers by using `LoggingService.addLogger` and `LoggingService.removeLogger`.
 *
 * You can set the `LogLevel` by setting `LoggingService.logLevel` with flags
 * from [LogLevel](/arc.js/api/enums/LogLevel/), or by using the [ConfigService](/Configuration.md#logging).
 *
 * Logically, LogLevels are simply or'd together, there is no hierarchy to them.
 */ export class LoggingService { public static loggers : Array < ILogger > = [ new ConsoleLogger ( ) ] ; public static logLevel : LogLevel = LogLevel . none ; public static moduleName : string = "Arc.js" ; public static debug ( message ) { LoggingService . loggers . forEach ( ( logger ) => { logger . debug ( message ) ; } ) ; } public static info ( message ) { LoggingService . loggers . forEach ( ( logger ) => { logger . info ( message ) ; } ) ; } public static warn ( message ) { LoggingService . loggers . forEach ( ( logger ) => { logger . warn ( message ) ; } ) ; } public static error ( message ) { LoggingService . loggers . forEach ( ( logger ) => { logger . error ( message ) ; } ) ; } param message param level public static message ( message , level = LoggingService . logLevel ) { if ( level === LogLevel . none ) { return ; } let messaged = false ; if ( level & LogLevel . error ) { LoggingService . error ( message ) ; messaged = true ; } if ( ! messaged && ( level & LogLevel . warn ) ) { LoggingService . warn ( message ) ; messaged = true ; } if ( ! messaged && ( level & LogLevel . info ) ) { LoggingService . info ( message ) ; messaged = true ; } if ( ! messaged && ( level & LogLevel . debug ) ) { LoggingService . debug ( message ) ; } } public static addLogger ( logger ) { LoggingService . loggers . push ( logger ) ; } public static removeLogger ( logger ) { const ndx = LoggingService . loggers . indexOf ( logger ) ; if ( ndx >= 0 ) { LoggingService . loggers . splice ( ndx , 1 ) ; } } public static stringifyObject ( obj ) { return JSON . stringify ( obj ) ; } }