import { LogLevel , LogLevelOptions } from './LogLevel' ; import { MethodFactory } from './MethodFactory' ; import { PrefixFactory } from './PrefixFactory' ; export * from './LogLevel' ; export * from './MethodFactory' ; export * from './PrefixFactory' ; const factories = Symbol ( 'log-factories' ) ; class DefaultLogger extends LogLevel { private cache : Record < string , LogLevel > ; constructor ( ) { super ( { name : 'default' } ) ; this . cache = { default : this } ; this [ factories as any ] = { MethodFactory , PrefixFactory } ; } get factories ( ) { return this [ factories as any ] ; } get loggers ( ) { return this . cache ; } create ( opts ) { let options ; if ( typeof opts === 'string' ) { options = { name : opts } ; } else { options = Object . assign ( { } , opts ) ; } if ( ! options . id ) { options . id = options . name ! . toString ( ) ; } const { name , id } = options ; const defaults = { level : this . level } ; if ( typeof name !== 'string' || ! name || ! name . length ) { throw new TypeError ( 'You must supply a name when creating a logger.' ) ; } let logger = this . cache [ id ] ; if ( ! logger ) { logger = new LogLevel ( Object . assign ( { } , defaults , options ) ) ; this . cache [ id ] = logger ; } return logger ; } } export default new DefaultLogger ( ) ;