44 *--------------------------------------------------------------------------------------------*/
55
66import { ILogService , LogLevel , AbstractLogService } from 'vs/platform/log/common/log' ;
7- import { ExtHostLogServiceShape } from 'vs/workbench/api/common/extHost.protocol' ;
7+ import { ExtHostLogServiceShape , MainThreadLogShape , MainContext } from 'vs/workbench/api/common/extHost.protocol' ;
88import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService' ;
99import { IExtHostOutputService } from 'vs/workbench/api/common/extHostOutput' ;
10- import * as vscode from 'vscode' ;
10+ import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService' ;
11+ import { joinPath } from 'vs/base/common/resources' ;
12+ import { ExtensionHostLogFileName } from 'vs/workbench/services/extensions/common/extensions' ;
13+ import { UriComponents } from 'vs/base/common/uri' ;
14+ import { localize } from 'vs/nls' ;
1115
1216export class ExtHostLogService extends AbstractLogService implements ILogService , ExtHostLogServiceShape {
1317
1418 _serviceBrand : any ;
1519
16- private readonly _logChannel : vscode . OutputChannel ;
20+ private readonly _proxy : MainThreadLogShape ;
21+ private readonly _logFile : UriComponents ;
1722
1823 constructor (
24+ @IExtHostRpcService rpc : IExtHostRpcService ,
1925 @IExtHostInitDataService initData : IExtHostInitDataService ,
2026 @IExtHostOutputService extHostOutputService : IExtHostOutputService
2127 ) {
2228 super ( ) ;
29+ const logFile = joinPath ( initData . logsLocation , `${ ExtensionHostLogFileName } .log` ) ;
30+ this . _proxy = rpc . getProxy ( MainContext . MainThreadLog ) ;
31+ this . _logFile = logFile . toJSON ( ) ;
2332 this . setLevel ( initData . logLevel ) ;
24- this . _logChannel = extHostOutputService . createOutputChannel ( 'Log ( Worker Extension Host)' ) ;
33+ extHostOutputService . createOutputChannelFromLogFile ( localize ( 'name' , " Worker Extension Host" ) , logFile ) ;
2534 }
2635
2736 $setLevel ( level : LogLevel ) : void {
@@ -30,55 +39,37 @@ export class ExtHostLogService extends AbstractLogService implements ILogService
3039
3140 trace ( _message : string , ..._args : any [ ] ) : void {
3241 if ( this . getLevel ( ) <= LogLevel . Trace ) {
33- this . _logChannel . appendLine ( this . _format ( arguments ) ) ;
42+ this . _proxy . $log ( this . _logFile , LogLevel . Trace , Array . from ( arguments ) ) ;
3443 }
3544 }
3645
3746 debug ( _message : string , ..._args : any [ ] ) : void {
3847 if ( this . getLevel ( ) <= LogLevel . Debug ) {
39- this . _logChannel . appendLine ( this . _format ( arguments ) ) ;
48+ this . _proxy . $log ( this . _logFile , LogLevel . Debug , Array . from ( arguments ) ) ;
4049 }
4150 }
4251
4352 info ( _message : string , ..._args : any [ ] ) : void {
4453 if ( this . getLevel ( ) <= LogLevel . Info ) {
45- this . _logChannel . appendLine ( this . _format ( arguments ) ) ;
54+ this . _proxy . $log ( this . _logFile , LogLevel . Info , Array . from ( arguments ) ) ;
4655 }
4756 }
4857
4958 warn ( _message : string , ..._args : any [ ] ) : void {
5059 if ( this . getLevel ( ) <= LogLevel . Warning ) {
51- this . _logChannel . appendLine ( this . _format ( arguments ) ) ;
60+ this . _proxy . $log ( this . _logFile , LogLevel . Warning , Array . from ( arguments ) ) ;
5261 }
5362 }
5463
5564 error ( _message : string | Error , ..._args : any [ ] ) : void {
5665 if ( this . getLevel ( ) <= LogLevel . Error ) {
57- this . _logChannel . appendLine ( this . _format ( arguments ) ) ;
66+ this . _proxy . $log ( this . _logFile , LogLevel . Error , Array . from ( arguments ) ) ;
5867 }
5968 }
6069
6170 critical ( _message : string | Error , ..._args : any [ ] ) : void {
6271 if ( this . getLevel ( ) <= LogLevel . Critical ) {
63- this . _logChannel . appendLine ( String ( arguments ) ) ;
72+ this . _proxy . $log ( this . _logFile , LogLevel . Critical , Array . from ( arguments ) ) ;
6473 }
6574 }
66-
67- private _format ( args : any ) : string {
68- let result = '' ;
69-
70- for ( let i = 0 ; i < args . length ; i ++ ) {
71- let a = args [ i ] ;
72-
73- if ( typeof a === 'object' ) {
74- try {
75- a = JSON . stringify ( a ) ;
76- } catch ( e ) { }
77- }
78-
79- result += ( i > 0 ? ' ' : '' ) + a ;
80- }
81-
82- return result ;
83- }
8475}
0 commit comments