@@ -13,10 +13,11 @@ import * as os from 'os';
1313import * as electron from './utils/electron' ;
1414import { Reader } from './utils/wireProtocol' ;
1515
16- import { workspace , window , Uri , CancellationToken , Disposable , OutputChannel , Memento , MessageItem , QuickPickItem , EventEmitter , Event , commands , WorkspaceConfiguration } from 'vscode' ;
16+ import { workspace , window , Uri , CancellationToken , Disposable , Memento , MessageItem , QuickPickItem , EventEmitter , Event , commands , WorkspaceConfiguration } from 'vscode' ;
1717import * as Proto from './protocol' ;
1818import { ITypescriptServiceClient , ITypescriptServiceClientHost , API } from './typescriptService' ;
1919import { TypeScriptServerPlugin } from './utils/plugins' ;
20+ import Logger from './utils/logger' ;
2021
2122import * as VersionStatus from './utils/versionStatus' ;
2223import * as is from './utils/is' ;
@@ -141,7 +142,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
141142 private _checkGlobalTSCVersion : boolean ;
142143 private _experimentalAutoBuild : boolean ;
143144 private trace : Trace ;
144- private _output : OutputChannel ;
145+ private readonly logger : Logger = new Logger ( ) ;
145146 private tsServerLogFile : string | null = null ;
146147 private tsServerLogLevel : TsServerLogLevel = TsServerLogLevel . Off ;
147148 private servicePromise : Thenable < cp . ChildProcess > | null ;
@@ -291,13 +292,6 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
291292 return this . _onTypesInstallerInitializationFailed . event ;
292293 }
293294
294- private get output ( ) : OutputChannel {
295- if ( ! this . _output ) {
296- this . _output = window . createOutputChannel ( localize ( 'channelName' , 'TypeScript' ) ) ;
297- }
298- return this . _output ;
299- }
300-
301295 private readTrace ( ) : Trace {
302296 let result : Trace = Trace . fromString ( workspace . getConfiguration ( ) . get < string > ( 'typescript.tsserver.trace' , 'off' ) ) ;
303297 if ( result === Trace . Off && ! ! process . env . TSS_TRACE ) {
@@ -331,54 +325,20 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
331325 return this . _onReady . promise ;
332326 }
333327
334- private data2String ( data : any ) : string {
335- if ( data instanceof Error ) {
336- if ( is . string ( data . stack ) ) {
337- return data . stack ;
338- }
339- return ( data as Error ) . message ;
340- }
341- if ( is . boolean ( data . success ) && ! data . success && is . string ( data . message ) ) {
342- return data . message ;
343- }
344- if ( is . string ( data ) ) {
345- return data ;
346- }
347- return data . toString ( ) ;
348- }
349-
350328 public info ( message : string , data ?: any ) : void {
351- this . output . appendLine ( `[Info - ${ ( new Date ( ) . toLocaleTimeString ( ) ) } ] ${ message } ` ) ;
352- if ( data ) {
353- this . output . appendLine ( this . data2String ( data ) ) ;
354- }
329+ this . logger . info ( message , data ) ;
355330 }
356331
357332 public warn ( message : string , data ?: any ) : void {
358- this . output . appendLine ( `[Warn - ${ ( new Date ( ) . toLocaleTimeString ( ) ) } ] ${ message } ` ) ;
359- if ( data ) {
360- this . output . appendLine ( this . data2String ( data ) ) ;
361- }
333+ this . logger . warn ( message , data ) ;
362334 }
363335
364336 public error ( message : string , data ?: any ) : void {
365- // See https://github.com/Microsoft/TypeScript/issues/10496
366- if ( data && data . message === 'No content available.' ) {
367- return ;
368- }
369- this . output . appendLine ( `[Error - ${ ( new Date ( ) . toLocaleTimeString ( ) ) } ] ${ message } ` ) ;
370- if ( data ) {
371- this . output . appendLine ( this . data2String ( data ) ) ;
372- }
373- // this.output.show(true);
337+ this . logger . error ( message , data ) ;
374338 }
375339
376340 private logTrace ( message : string , data ?: any ) : void {
377- this . output . appendLine ( `[Trace - ${ ( new Date ( ) . toLocaleTimeString ( ) ) } ] ${ message } ` ) ;
378- if ( data ) {
379- this . output . appendLine ( this . data2String ( data ) ) ;
380- }
381- // this.output.show(true);
341+ this . logger . logLevel ( 'Trace' , message , data ) ;
382342 }
383343
384344 private get packageInfo ( ) : IPackageInfo | null {
0 commit comments