export interface Output { log ( ... args ) : void ; warn ( ... args ) : void ; error ( ... args ) : void ; } export enum Level { DEBUG = 10 , INFO = 20 , WARNING = 30 , ERROR = 40 , CRITICAL = 50 } export interface Options { out : Output ; level : Level ; } const NAME = 'vdvsl' ; export class Logger { private out : Output = window . console ; private level : Level = Level . DEBUG ; constructor ( { out , level } ) { this . out = out ; this . level = level ; } debug ( ... args ) { if ( Level . DEBUG < this . level ) { return ; } this . out . log . apply ( this . out , this . withPrefix ( args ) ) ; } info ( ... args ) { if ( Level . INFO < this . level ) { return ; } this . out . log . apply ( this . out , this . withPrefix ( args ) ) ; } warning ( ... args ) { if ( Level . WARNING < this . level ) { return ; } this . out . warn . apply ( this . out , this . withPrefix ( args ) ) ; } error ( ... args ) { if ( Level . ERROR < this . level ) { return ; } this . out . error . apply ( this . out , this . withPrefix ( args ) ) ; } critical ( ... args ) { if ( Level . CRITICAL < this . level ) { return ; } this . out . error . apply ( this . out , this . withPrefix ( args ) ) ; } withPrefix ( args ) { return [ `[${ NAME }] ` ] . concat ( args ) ; } } export default new Logger ( { out : window . console , level : ( process && process . env && process . env . NODE_ENV === 'development' ) ? Level . DEBUG : Level . ERROR } ) ;