import util from "util" ; import chalk from "chalk" ; /**
 * Log levels to indicate importance of the logged message.
 * Every level corresponds to a certain color.
 *
 * - INFO: no color
 * - WARN: yellow
 * - ERROR: red
 * - DEBUG: gray
 *
 * Messages with DEBUG level are only displayed if explicitly enabled.
 */ export const enum LogLevel { INFO = "info" , WARN = "warn" , ERROR = "error" , DEBUG = "debug" } /**
 * Represents a logging device which can be used directly as a function (for INFO logging)
 * but also has dedicated logging functions for respective logging levels.
 */ export interface Logging { prefix : string ; ( message , ... parameters ) : void ; info ( message , ... parameters ) : void ; warn ( message , ... parameters ) : void ; error ( message , ... parameters ) : void ; debug ( message , ... parameters ) : void ; log ( level , message , ... parameters ) : void ; } interface IntermediateLogging { prefix ? : string ; ( message , ... parameters ) : void ; info ? ( message , ... parameters ) : void ; warn ? ( message , ... parameters ) : void ; error ? ( message , ... parameters ) : void ; debug ? ( message , ... parameters ) : void ; log ? ( level , message , ... parameters ) : void ; } /**
 * Logger class
 */ export class Logger { public static readonly internal = new Logger ( ) ; private static readonly loggerCache = new Map < string , Logging > ( ) ; private static debugEnabled = false ; private static timestampEnabled = true ; readonly prefix ? : string ; constructor ( prefix ? ) { this . prefix = prefix ; } param prefix { string } static withPrefix ( prefix ) { const loggerStuff = Logger . loggerCache . get ( prefix ) ; if ( loggerStuff ) { return loggerStuff ; } else { const logger = new Logger ( prefix ) ; const log = logger . info . bind ( logger ) ; log . info = logger . info ; log . warn = logger . warn ; log . error = logger . error ; log . debug = logger . debug ; log . log = logger . log ; log . prefix = logger . prefix ; const logging = log ; Logger . loggerCache . set ( prefix , logging ) ; return logging ; } } param enabled { boolean } public static setDebugEnabled ( enabled = true ) { Logger . debugEnabled = enabled ; } param enabled { boolean } public static setTimestampEnabled ( enabled = true ) { Logger . timestampEnabled = enabled ; } /**
     * Forces color in logging output, even if it seems like color is unsupported.
     */ public static forceColor ( ) { chalk . level = 1 ; } public info ( message , ... parameters ) { this . log ( LogLevel . INFO , message , ... parameters ) ; } public warn ( message , ... parameters ) { this . log ( LogLevel . WARN , message , ... parameters ) ; } public error ( message , ... parameters ) { this . log ( LogLevel . ERROR , message , ... parameters ) ; } public debug ( message , ... parameters ) { this . log ( LogLevel . DEBUG , message , ... parameters ) ; } public log ( level , message , ... parameters ) { if ( level === LogLevel . DEBUG && ! Logger . debugEnabled ) { return ; } message = util . format ( message , ... parameters ) ; let loggingFunction = console . log ; switch ( level ) { case LogLevel . WARN : message = chalk . yellow ( message ) ; loggingFunction = console . error ; break ; case LogLevel . ERROR : message = chalk . red ( message ) ; loggingFunction = console . error ; break ; case LogLevel . DEBUG : message = chalk . gray ( message ) ; break ; } if ( this . prefix ) { message = getLogPrefix ( this . prefix ) + " " + message ; } if ( Logger . timestampEnabled ) { const date = new Date ( ) ; message = chalk . white ( `[${ date . toLocaleString ( ) }] ` ) + message ; } loggingFunction ( message ) ; } } param prefix { string } deprecated please use  Logger . withPrefix directly
  export function withPrefix ( prefix ) { return Logger . withPrefix ( prefix ) ; } param prefix export function getLogPrefix ( prefix ) { return chalk . cyan ( `[${ prefix }]` ) ; } param enabled { boolean } deprecated please use  Logger . setDebugEnabled directly
  export function setDebugEnabled ( enabled = true ) { Logger . setDebugEnabled ( enabled ) ; } param enabled { boolean } deprecated please use  Logger . setTimestampEnabled directly
  export function setTimestampEnabled ( enabled = true ) { Logger . setTimestampEnabled ( enabled ) ; } deprecated please use  Logger . forceColor directly
  export function forceColor ( ) { chalk . level = 1 ; }