import { LogType , OutputAdapter } from 'ibm-blockchain-platform-common' ; import * as vscode from 'vscode' ; export abstract class VSCodeOutputAdapter extends OutputAdapter { public channelName : string ; private outputChannel : vscode . OutputChannel ; private console : boolean = ! ! process . env . BLOCKCHAIN_VSCODE_CONSOLE_OUTPUT ; protected constructor ( channelName ) { super ( ) ; this . channelName = channelName ; this . outputChannel = vscode . window . createOutputChannel ( channelName ) ; } param type { LogType } param popupMessage { String } param outputMessage { String } param stackTrace { String } param skipNextLine { Boolean } returns { void } log ( type , popupMessage , outputMessage ? , stackTrace ? , skipNextLine ? ) { if ( ! popupMessage && ! outputMessage ) { return ; } if ( ! outputMessage ) { outputMessage = popupMessage ; } if ( this . console ) { super . log ( type , popupMessage , outputMessage , stackTrace ) ; } this . appendLine ( type , outputMessage , skipNextLine ) ; if ( popupMessage ) { if ( type === LogType . ERROR ) { vscode . window . showErrorMessage ( popupMessage ) ; } else { vscode . window . showInformationMessage ( popupMessage ) ; } } if ( stackTrace ) { this . appendLine ( type , stackTrace ) ; } } show ( ) { this . outputChannel . show ( ) ; } setConsole ( console ) { this . console = console ; } appendLine ( type , value , skipNextLine ? ) { this . outputChannel . appendLine ( `[${ this . getTimestamp ( ) }] [${ type }] ${ value }` ) ; if ( skipNextLine ) { this . outputChannel . appendLine ( '' ) ; } } getTimestamp ( ) { let dateTime = new Date ( ) . toLocaleString ( ) ; dateTime = dateTime . replace ( ',' , '' ) ; return dateTime ; } }