export enum LogStyle { verbose = 'info' , info = 'info' , imp = 'imp' , warn = 'warn' , err = 'err' } export enum LogLevel { verbose , debug , important , warn } export interface WriteableStream { write : ( message : string ) => void ; } /**
 * Logs to the console based on log level
 */ export class DiagnosticsLoggerBase { public readonly logLevel : LogLevel ; protected logger : any ; protected readonly fileLogger : WriteableStream ; protected readonly includeStackTrace : boolean ; protected readonly logToFiles ; constructor ( logLevel , logToFiles , fileLogger ? ) { this . logLevel = logLevel ; this . includeStackTrace = this . logLevel <= LogLevel . debug ? true : false ; this . logToFiles = logToFiles ; this . fileLogger = fileLogger ; } param content public write ( content ) { this . debug ( content ) ; } public verbose ( content ) { if ( this . logLevel > LogLevel . verbose ) { return ; } this . log ( LogStyle . verbose , content ) ; } public debug ( content ) { if ( this . logLevel > LogLevel . debug ) { return ; } this . log ( LogStyle . info , content ) ; } public imp ( content ) { if ( this . logLevel > LogLevel . important ) { return ; } this . log ( LogStyle . imp , content ) ; } public warn ( content ) { this . log ( LogStyle . warn , content ) ; } public err ( content ) { this . log ( LogStyle . err , content ) ; } public log ( style , content ) { throw new Error ( 'Not implmented in base class' ) ; } } export interface ServiceLog { [ key ] : any ; } /**
 * Logs content from app services to files and/or console
 */ export class ServiceLoggerBase { public readonly service : string ; public readonly logToFiles : boolean ; public readonly logToConsole : boolean ; public readonly logLevel : LogLevel ; protected readonly stream : WriteableStream ; constructor ( service , logLevel , logToFiles , stream ? ) { this . service = service ; this . logLevel = logLevel ; this . logToFiles = logToFiles ; this . stream = stream ; this . logToConsole = this . logLevel <= LogLevel . debug ; } param serviceLog public log ( serviceLog ) { this . write ( this . format ( serviceLog ) ) ; } param message public write ( message ) { const now = new Date ( ) ; message = `[${ now . toUTCString ( ) }] service=${ this . service } ${ message }` ; if ( this . logToConsole ) { console . log ( message ) ; } } param serviceLog public format ( serviceLog ) { throw new Error ( 'Not implmented in base class' ) ; } } export interface FileLoggerFactory { ( logPath ) : WriteableStream ; } /**
 * Configuration options related to logging.
 */ export interface LoggerConfig { /**
     * If 'logToFiles' is true, this contains the path on the local filesystem where log files will
     * be written.
     */ logDirectory ? : string ; /**
     * Log level. Defaults to 2. Lower numbers are more verbose.
     */ logLevel ? : LogLevel ; /**
     * Controls whether logs get persisted to the file system.
     */ logToFiles ? : boolean ; } const DEFAULT_LOG_CONFIG = { logLevel : LogLevel . important , logToFiles : false , } ; /**
//  * Global Logger factory
//  */ export class LoggerProviderBase { public readonly config : LoggerConfig ; protected readonly _diagnosticLogger : DiagnosticsLoggerBase ; protected readonly _fileLoggerFactory : FileLoggerFactory ; constructor ( config = { } , fileLoggerFactory ? ) { this . config = { logLevel : config . logLevel !== undefined ? config . logLevel : DEFAULT_LOG_CONFIG . logLevel , logToFiles : config . logToFiles !== undefined ? config . logToFiles : DEFAULT_LOG_CONFIG . logToFiles , logDirectory : config . logDirectory , } ; this . _fileLoggerFactory = fileLoggerFactory ; if ( this . config . logToFiles && ! this . _fileLoggerFactory ) { throw new Error ( 'Must provide a FileLoggerFactory in order to log to files' ) ; } this . _diagnosticLogger = this . _makeDiagnosticLogger ( ) ; } protected _makeDiagnosticLogger ( ) { throw new Error ( 'Not implmented in base class' ) ; } public getDiagnosticsLogger ( ) { return this . _diagnosticLogger ; } public makeServiceLogger ( serviceName ) { throw new Error ( 'Not implmented in base class' ) ; } }