import * as vscode from 'vscode' ; import { ExtensionComponent } from '../extensionComponent' ; type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERR' ; /**
 * Log to the "OUTPUT" channel. Add date and log level.
 */ export class LogManager implements ExtensionComponent { private _statusBar ! : vscode . StatusBarItem ; private _outputChannel ! : vscode . OutputChannel ; constructor ( ) { this . _statusBar = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right ) ; this . _statusBar . tooltip = 'JFrog Xray vulnerabilities scanning status' ; this . _statusBar . command = 'jfrog.xray.showOutput' ; } activate ( ) { this . _outputChannel = vscode . window . createOutputChannel ( 'JFrog' ) ; this . _statusBar . show ( ) ; return this ; } param message param level public logMessage ( message , level , focusOutput = false ) { if ( ! ! message ) { const title = new Date ( ) . toLocaleTimeString ( ) ; this . _outputChannel . appendLine ( `[${ level } - ${ title }] ${ message }` ) ; if ( focusOutput ) { this . showOutput ( ) ; } } } param error param shouldToast public logError ( error , shouldToast ) { this . setFailed ( ) ; this . logMessage ( error . name , 'ERR' ) ; if ( error . message ) { this . _outputChannel . appendLine ( error . message ) ; if ( shouldToast ) { vscode . window . showErrorMessage ( error . message ) ; this . showOutput ( ) ; } } if ( error . stack ) { this . _outputChannel . appendLine ( error . stack ) ; } } /**
     * Show JFrog Output tab.
     */ public showOutput ( ) { this . _outputChannel . show ( true ) ; } /**
     * Set success in the JFrog status bar.
     */ public setSuccess ( ) { this . _statusBar . text = 'JFrog: $(check)' ; } /**
     * Set failure in the JFrog status bar.
     */ private setFailed ( ) { this . _statusBar . text = 'JFrog: $(error)' ; } }