const PAUSE_LOG_TIME = 2 ; /**
 * Class for logging.
 * This allows to instantiate a new class and log there into an own channel.
 * Or, you can use static methods to log globally.
 * When logging into a channel this is logged by vscode also into a file located
 * at /Users/.../Library/Application Support/Code.
 * You can find it by opening the command palette and typing "Developer: open Extensions logs Folder".
 */ export class Log { protected logOutput ; protected lastLogTime = Date . now ( ) ; protected callerNameIndex = - 1 ; protected cache : Array < string > ; protected cacheLength = 0 ; protected cacheLogsLost = false ; protected cacheTime = 100 ; param channelOutput public static init ( channelOutput ) { LogGlobal . init ( channelOutput ) ; LogGlobal . callerNameIndex ++ ; } param args public static log ( ... args ) { LogGlobal . log ( ... args ) ; } return public static isEnabled ( ) { return LogGlobal . isEnabled ( ) ; } param channelOutput param callerName public init ( channelOutput , callerName = true ) { if ( this . logOutput ) this . logOutput . dispose ( ) ; this . logOutput = channelOutput ; if ( callerName ) this . callerNameIndex = 3 ; } param args public log ( ... args ) { const diffTime = ( Date . now ( ) - this . lastLogTime ) / 1000 ; let outputcache = false ; if ( diffTime > PAUSE_LOG_TIME ) { this . outputCache ( ) ; this . write ( '...' ) ; this . write ( 'Pause for ' + diffTime + ' secs.' ) ; this . write ( '...' ) ; this . outputCache ( ) ; outputcache = true ; } this . write ( ... args ) ; if ( outputcache ) this . outputCache ( ) ; this . lastLogTime = Date . now ( ) ; } return public isEnabled ( ) { return ( this . logOutput != undefined ) ; } param format param args protected write ( ... args ) { const text = args . map ( elem => elem . toString ( ) ) . join ( ', ' ) ; try { this . appendLine ( text ) ; } catch ( e ) { } } param text public appendLine ( text ) { if ( this . logOutput ) { if ( this . cache ) { if ( this . cache . length >= this . cacheLength ) { this . cache . shift ( ) ; this . cacheLogsLost = true ; } if ( text == undefined ) console . log ( "" ) ; this . cache . push ( text ) ; if ( this . cache . length == 1 ) { setTimeout ( ( ) => { this . outputCache ( ) ; } , this . cacheTime ) ; } } else { this . logOutput . appendLine ( text ) ; } } } /**
     * Outputs the cache to console.
     * Does nothing if no cache is set.
     */ public outputCache ( ) { if ( this . cache ) { if ( this . cacheLogsLost ) { this . logOutput . appendLine ( '[...]' ) ; } for ( const text of this . cache ) { this . logOutput . appendLine ( text ) ; } this . cache . length = 0 ; this . cacheLogsLost = false ; } } param length public setCacheLength ( length ) { this . cache = ( length > 0 ) ? new Array < string > ( ) : undefined as any ; this . cacheLength = length ; this . cacheLogsLost = false ; } returns protected callerName ( ) { return '' ; if ( this . callerNameIndex < 0 ) return '' ; try { throw new Error ( ) ; } catch ( e ) { try { return e . stack . split ( 'at ' ) [ this . callerNameIndex ] . split ( ' ' ) [ 0 ] + ': ' ; } catch ( e ) { return 'Unknown' ; } } } } export let LogGlobal = new Log ( ) ; export let LogCustomCode = new Log ( ) ; LogCustomCode . setCacheLength ( 100 ) ; export let LogSocket = new Log ( ) ; export let LogSocketCommands ;