import { injectable } from 'inversify' ; export const enum LogLevel { Info = 0 , Warn , Error , Never } export function logLevelFromString ( s , defaultLogLevel = LogLevel . Never ) { switch ( s ) { case 'Info' : return LogLevel . Info ; case 'Warn' : return LogLevel . Warn ; case 'Error' : return LogLevel . Error ; case 'Never' : return LogLevel . Never ; default : return defaultLogLevel ; } } export type LogDomain = 'Extension' | 'IoC' | 'LogPointManager' | 'SessionManager' | 'Session' | 'DecorationManager' | 'OperatorLogPointRecommender' | 'WorkspaceMonitor' | 'Detector' | 'TelemetryBridge' | 'AnalyticsReporter' ; export const ILogger = Symbol ( 'ILogger' ) ; export interface ILogger { log ( level , domain , message ) : void ; info ( domain , message ) : void ; warn ( domain , message ) : void ; error ( domain , message ) : void ; } export interface ILogSink { log : ( level : LogLevel , domain : LogDomain , message : string ) => void ; } @ injectable ( ) export default class Logger implements ILogger { constructor ( private readonly sinks , private readonly minLogLevel = LogLevel . Never ) { } log ( level , domain , message ) { if ( level < this . minLogLevel ) { return ; } for ( const target of this . sinks ) { target . log ( level , domain , message ) ; } } info ( domain , message ) { this . log ( LogLevel . Info , domain , message ) ; } warn ( domain , message ) { this . log ( LogLevel . Warn , domain , message ) ; } error ( domain , message ) { this . log ( LogLevel . Error , domain , message ) ; } returns static nullLogger ( ) { return new Logger ( [ ] ) ; } }