import { window } from 'vscode' ; type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE' ; export class LoggingService { private outputChannel = window . createOutputChannel ( 'Modern Fortran' ) ; private logLevel : LogLevel = 'INFO' ; public setOutputLevel ( logLevel ) { this . logLevel = logLevel ; } param message public logDebug ( message , data ? ) { if ( this . logLevel === 'NONE' || this . logLevel === 'INFO' || this . logLevel === 'WARN' || this . logLevel === 'ERROR' ) { return ; } this . logMessage ( message , 'INFO' ) ; if ( data ) { this . logObject ( data ) ; } } param message public logInfo ( message , data ? ) { if ( this . logLevel === 'NONE' || this . logLevel === 'WARN' || this . logLevel === 'ERROR' ) { return ; } this . logMessage ( message , 'INFO' ) ; if ( data ) { this . logObject ( data ) ; } } param message public logWarning ( message , data ? ) { if ( this . logLevel === 'NONE' || this . logLevel === 'ERROR' ) { return ; } this . logMessage ( message , 'WARN' ) ; if ( data ) { this . logObject ( data ) ; } } public logError ( message , error ? ) { if ( this . logLevel === 'NONE' ) { return ; } this . logMessage ( message , 'ERROR' ) ; if ( typeof error === 'string' ) { this . outputChannel . appendLine ( error ) ; } else if ( error ?. message || error ?. stack ) { if ( error ?. message ) { this . logMessage ( error . message , 'ERROR' ) ; } if ( error ?. stack ) { this . outputChannel . appendLine ( error . stack ) ; } } else if ( error ) { this . logObject ( error ) ; } } public show ( ) { this . outputChannel . show ( ) ; } private logObject ( data ) { const message = JSON . stringify ( data , null , 2 ) ; this . outputChannel . appendLine ( message ) ; } param message private logMessage ( message , logLevel ) { const title = new Date ( ) . toLocaleTimeString ( ) ; this . outputChannel . appendLine ( `["${ logLevel }" - ${ title }] ${ message }` ) ; } }