/**
 * Severity levels for log entries
 */ export enum LogLevel { ERROR = 'error' , WARN = 'warn' , INFO = 'info' , DEBUG = 'debug' } /**
 * Interface for objects where objects in this package's logs can be sent (can be used as `logger` option).
 */ export interface Logger { param msg debug ( ... msg ) : void ; param msg info ( ... msg ) : void ; param msg warn ( ... msg ) : void ; param msg error ( ... msg ) : void ; param level setLevel ( level ) : void ; /**
     * Return the current LogLevel.
     */ getLevel ( ) : LogLevel ; param name setName ( name ) : void ; } /**
 * Default logger which logs to stdout and stderr
 */ export class ConsoleLogger implements Logger { /** Setting for level */ private level : LogLevel ; /** Name */ private name : string ; /** Map of labels for each log level */ private static labels : Map < LogLevel , string > = ( ( ) => { const entries = Object . entries ( LogLevel ) as ( [ string , LogLevel ] ) [ ] ; const map = entries . map ( ( [ key , value ] ) => [ value , `[${ key }] ` ] as [ LogLevel , string ] ) ; return new Map ( map ) ; } ) ( ) ; /** Map of severity as comparable numbers for each log level */ private static severity : { [ key in LogLevel ] : number ; } = { [ LogLevel . ERROR ] : 400 , [ LogLevel . WARN ] : 300 , [ LogLevel . INFO ] : 200 , [ LogLevel . DEBUG ] : 100 , } ; public constructor ( ) { this . level = LogLevel . INFO ; this . name = '' ; } public getLevel ( ) { return this . level ; } /**
     * Sets the instance's log level so that only messages which are equal or more severe are output to the console.
     */ public setLevel ( level ) { this . level = level ; } /**
     * Set the instance's name, which will appear on each log line before the message.
     */ public setName ( name ) { this . name = name ; } /**
     * Log a debug message
     */ public debug ( ... msg ) { if ( ConsoleLogger . isMoreOrEqualSevere ( LogLevel . DEBUG , this . level ) ) { console . debug ( ConsoleLogger . labels . get ( LogLevel . DEBUG ) , this . name , ... msg ) ; } } /**
     * Log an info message
     */ public info ( ... msg ) { if ( ConsoleLogger . isMoreOrEqualSevere ( LogLevel . INFO , this . level ) ) { console . info ( ConsoleLogger . labels . get ( LogLevel . INFO ) , this . name , ... msg ) ; } } /**
     * Log a warning message
     */ public warn ( ... msg ) { if ( ConsoleLogger . isMoreOrEqualSevere ( LogLevel . WARN , this . level ) ) { console . warn ( ConsoleLogger . labels . get ( LogLevel . WARN ) , this . name , ... msg ) ; } } /**
     * Log an error message
     */ public error ( ... msg ) { if ( ConsoleLogger . isMoreOrEqualSevere ( LogLevel . ERROR , this . level ) ) { console . error ( ConsoleLogger . labels . get ( LogLevel . ERROR ) , this . name , ... msg ) ; } } /**
     * Helper to compare two log levels and determine if a is equal or more severe than b
     */ private static isMoreOrEqualSevere ( a , b ) { return ConsoleLogger . severity [ a ] >= ConsoleLogger . severity [ b ] ; } }