'use strict' ; import * as vscode from 'vscode' ; import * as os from 'os' ; import { CppSettings } from './LanguageServer/settings' ; let Subscriber ; export function subscribeToAllLoggers ( subscriber ) { Subscriber = subscriber ; } export class Logger { private writer : ( message : string ) => void ; constructor ( writer ) { this . writer = writer ; } public append ( message ) { this . writer ( message ) ; if ( Subscriber ) { Subscriber ( message ) ; } } public appendLine ( message ) { this . writer ( message + os . EOL ) ; if ( Subscriber ) { Subscriber ( message + os . EOL ) ; } } public showInformationMessage ( message , items ? ) { this . appendLine ( message ) ; if ( ! items ) { return vscode . window . showInformationMessage ( message ) ; } return vscode . window . showInformationMessage ( message , ... items ) ; } public showWarningMessage ( message , items ? ) { this . appendLine ( message ) ; if ( ! items ) { return vscode . window . showWarningMessage ( message ) ; } return vscode . window . showWarningMessage ( message , ... items ) ; } public showErrorMessage ( message , items ? ) { this . appendLine ( message ) ; if ( ! items ) { return vscode . window . showErrorMessage ( message ) ; } return vscode . window . showErrorMessage ( message , ... items ) ; } } let outputChannel ; export function getOutputChannel ( ) { if ( ! outputChannel ) { outputChannel = vscode . window . createOutputChannel ( "C/C++" ) ; const settings = new CppSettings ( ) ; const loggingLevel = settings . loggingLevel ; if ( ! ! loggingLevel && loggingLevel !== "None" && loggingLevel !== "Error" ) { outputChannel . appendLine ( `loggingLevel: ${ loggingLevel }` ) ; } } return outputChannel ; } export function showOutputChannel ( ) { getOutputChannel ( ) . show ( ) ; } let outputChannelLogger ; export function getOutputChannelLogger ( ) { if ( ! outputChannelLogger ) { outputChannelLogger = new Logger ( message => getOutputChannel ( ) . append ( message ) ) ; } return outputChannelLogger ; }