44 *--------------------------------------------------------------------------------------------*/
55
66import * as nls from 'vs/nls' ;
7+ import { join } from 'vs/base/common/path' ;
78import { Registry } from 'vs/platform/registry/common/platform' ;
89import { IWorkbenchActionRegistry , Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actions' ;
910import { SyncActionDescriptor } from 'vs/platform/actions/common/actions' ;
10- import { SetLogLevelAction } from 'vs/workbench/contrib/logs/common/logsActions' ;
11+ import { SetLogLevelAction , OpenLogsFolderAction } from 'vs/workbench/contrib/logs/common/logsActions' ;
12+ import * as Constants from 'vs/workbench/contrib/logs/common/logConstants' ;
13+ import { IWorkbenchContribution , IWorkbenchContributionsRegistry , Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions' ;
14+ import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
15+ import { IFileService , FileChangeType } from 'vs/platform/files/common/files' ;
16+ import { URI } from 'vs/base/common/uri' ;
17+ import { IOutputChannelRegistry , Extensions as OutputExt } from 'vs/workbench/contrib/output/common/output' ;
18+ import { Disposable } from 'vs/base/common/lifecycle' ;
19+ import { ILogService , LogLevel } from 'vs/platform/log/common/log' ;
20+ import { dirname } from 'vs/base/common/resources' ;
21+ import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle' ;
22+ import { isWeb } from 'vs/base/common/platform' ;
1123
1224const workbenchActionsRegistry = Registry . as < IWorkbenchActionRegistry > ( WorkbenchActionExtensions . WorkbenchActions ) ;
1325const devCategory = nls . localize ( 'developer' , "Developer" ) ;
14- workbenchActionsRegistry . registerWorkbenchAction ( new SyncActionDescriptor ( SetLogLevelAction , SetLogLevelAction . ID , SetLogLevelAction . LABEL ) , 'Developer: Set Log Level...' , devCategory ) ;
26+ workbenchActionsRegistry . registerWorkbenchAction ( new SyncActionDescriptor ( SetLogLevelAction , SetLogLevelAction . ID , SetLogLevelAction . LABEL ) , 'Developer: Set Log Level...' , devCategory ) ;
27+
28+ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
29+
30+ constructor (
31+ @IWorkbenchEnvironmentService private readonly environmentService : IWorkbenchEnvironmentService ,
32+ @ILogService private readonly logService : ILogService ,
33+ @IFileService private readonly fileService : IFileService
34+ ) {
35+ super ( ) ;
36+ if ( isWeb ) {
37+ this . registerWebContributions ( ) ;
38+ } else {
39+ this . registerNativeContributions ( ) ;
40+ }
41+ }
42+
43+ private registerWebContributions ( ) : void {
44+ Registry . as < IOutputChannelRegistry > ( OutputExt . OutputChannels ) . registerChannel ( { id : Constants . rendererLogChannelId , label : nls . localize ( 'rendererLog' , "Window" ) , file : this . environmentService . logFile , log : true } ) ;
45+ }
46+
47+ private registerNativeContributions ( ) : void {
48+ this . registerLogChannel ( Constants . mainLogChannelId , nls . localize ( 'mainLog' , "Main" ) , URI . file ( join ( this . environmentService . logsPath , `main.log` ) ) ) ;
49+ this . registerLogChannel ( Constants . sharedLogChannelId , nls . localize ( 'sharedLog' , "Shared" ) , URI . file ( join ( this . environmentService . logsPath , `sharedprocess.log` ) ) ) ;
50+ this . registerLogChannel ( Constants . rendererLogChannelId , nls . localize ( 'rendererLog' , "Window" ) , this . environmentService . logFile ) ;
51+
52+ const registerTelemetryChannel = ( level : LogLevel ) => {
53+ if ( level === LogLevel . Trace && ! Registry . as < IOutputChannelRegistry > ( OutputExt . OutputChannels ) . getChannel ( Constants . telemetryLogChannelId ) ) {
54+ this . registerLogChannel ( Constants . telemetryLogChannelId , nls . localize ( 'telemetryLog' , "Telemetry" ) , URI . file ( join ( this . environmentService . logsPath , `telemetry.log` ) ) ) ;
55+ }
56+ } ;
57+ registerTelemetryChannel ( this . logService . getLevel ( ) ) ;
58+ this . logService . onDidChangeLogLevel ( registerTelemetryChannel ) ;
59+
60+ const workbenchActionsRegistry = Registry . as < IWorkbenchActionRegistry > ( WorkbenchActionExtensions . WorkbenchActions ) ;
61+ const devCategory = nls . localize ( 'developer' , "Developer" ) ;
62+ workbenchActionsRegistry . registerWorkbenchAction ( new SyncActionDescriptor ( OpenLogsFolderAction , OpenLogsFolderAction . ID , OpenLogsFolderAction . LABEL ) , 'Developer: Open Logs Folder' , devCategory ) ;
63+ }
64+
65+ private async registerLogChannel ( id : string , label : string , file : URI ) : Promise < void > {
66+ const outputChannelRegistry = Registry . as < IOutputChannelRegistry > ( OutputExt . OutputChannels ) ;
67+ const exists = await this . fileService . exists ( file ) ;
68+ if ( exists ) {
69+ outputChannelRegistry . registerChannel ( { id, label, file, log : true } ) ;
70+ return ;
71+ }
72+
73+ const watcher = this . fileService . watch ( dirname ( file ) ) ;
74+ const disposable = this . fileService . onFileChanges ( e => {
75+ if ( e . contains ( file , FileChangeType . ADDED ) ) {
76+ watcher . dispose ( ) ;
77+ disposable . dispose ( ) ;
78+ outputChannelRegistry . registerChannel ( { id, label, file, log : true } ) ;
79+ }
80+ } ) ;
81+ }
82+
83+ }
84+
85+ Registry . as < IWorkbenchContributionsRegistry > ( WorkbenchExtensions . Workbench ) . registerWorkbenchContribution ( LogOutputChannels , LifecyclePhase . Restored ) ;
0 commit comments