import { Logger , logger } from 'vscode-debugadapter' ; import { timestamp } from './Utils/fsutils' ; export class OctaveLogger { public static logToConsole : boolean = false ; public static outputEnabled : boolean = true ; private static shouldOutput ( str ) { return OctaveLogger . outputEnabled && str . trim ( ) . length !== 0 ; } public static setup ( verbose , filename ) { const logLevel = ( verbose ? Logger . LogLevel . Verbose : Logger . LogLevel . Log ) ; OctaveLogger . outputEnabled = true ; if ( filename !== undefined ) { logger . setup ( logLevel , `${ filename }${ timestamp ( ) }.txt` , true ) ; } else { logger . setup ( logLevel , false ) ; } } public static verbose ( str ) { if ( this . shouldOutput ( str ) ) { if ( OctaveLogger . logToConsole ) { console . log ( str ) ; } logger . verbose ( str ) ; } } public static log ( str ) { if ( this . shouldOutput ( str ) ) { if ( OctaveLogger . logToConsole ) { console . log ( str ) ; } logger . log ( str ) ; } } public static warn ( str ) { if ( this . shouldOutput ( str ) ) { if ( OctaveLogger . logToConsole ) { console . warn ( str ) ; } logger . warn ( str ) ; } } public static error ( str ) { if ( this . shouldOutput ( str ) ) { if ( OctaveLogger . logToConsole ) { console . error ( str ) ; } logger . error ( str ) ; } } public static debug ( str ) { OctaveLogger . verbose ( str ) ; } }