Skip to content

Commit 2566318

Browse files
committed
Create ITerminalLogService
This will be the central place for all future terminal renderer-side logging, a new server is used to prevent needing to call createLogger in many files.
1 parent 3b53204 commit 2566318

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/vs/platform/terminal/common/terminal.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ThemeIcon } from 'vs/base/common/themables';
1313
import { ISerializableEnvironmentVariableCollections } from 'vs/platform/terminal/common/environmentVariable';
1414
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
1515
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
16+
import { ILogger } from 'vs/platform/log/common/log';
1617

1718
export const terminalTabFocusContextKey = new RawContextKey<boolean>('terminalTabFocusMode', false, true);
1819

@@ -952,3 +953,6 @@ export const ILocalPtyService = createDecorator<ILocalPtyService>('localPtyServi
952953
* **This service should only be used within the terminal component.**
953954
*/
954955
export interface ILocalPtyService extends IPtyService { }
956+
957+
export const ITerminalLogService = createDecorator<ITerminalLogService>('terminalLogService');
958+
export interface ITerminalLogService extends ILogger { }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { Disposable } from 'vs/base/common/lifecycle';
7+
import { Event } from 'vs/base/common/event';
8+
import { localize } from 'vs/nls';
9+
import { ILogger, ILoggerService, LogLevel } from 'vs/platform/log/common/log';
10+
import { ITerminalLogService } from 'vs/platform/terminal/common/terminal';
11+
12+
export class TerminalLogService extends Disposable implements ITerminalLogService {
13+
declare _serviceBrand: undefined;
14+
15+
private readonly _logger: ILogger;
16+
17+
get onDidChangeLogLevel(): Event<LogLevel> { return this._logger.onDidChangeLogLevel; }
18+
19+
constructor(@ILoggerService private readonly _loggerService: ILoggerService) {
20+
super();
21+
this._logger = this._loggerService.createLogger('terminal', { name: localize('terminalLoggerName', 'Terminal') });
22+
}
23+
24+
getLevel(): LogLevel { return this._logger.getLevel(); }
25+
setLevel(level: LogLevel): void { this._logger.setLevel(level); }
26+
trace(message: string, ...args: any[]): void { this.trace(message, args); }
27+
debug(message: string, ...args: any[]): void { this.debug(message, args); }
28+
info(message: string, ...args: any[]): void { this.info(message, args); }
29+
warn(message: string, ...args: any[]): void { this.warn(message, args); }
30+
error(message: string | Error, ...args: any[]): void { this.error(message, args); }
31+
flush(): void { this._logger.flush(); }
32+
}

src/vs/workbench/contrib/terminal/electron-sandbox/terminal.contribution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
77
import { registerMainProcessRemoteService } from 'vs/platform/ipc/electron-sandbox/services';
88
import { Registry } from 'vs/platform/registry/common/platform';
9-
import { ILocalPtyService, TerminalIpcChannels } from 'vs/platform/terminal/common/terminal';
9+
import { ILocalPtyService, ITerminalLogService, TerminalIpcChannels } from 'vs/platform/terminal/common/terminal';
1010
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
1111
import { ITerminalProfileResolverService } from 'vs/workbench/contrib/terminal/common/terminal';
1212
import { TerminalNativeContribution } from 'vs/workbench/contrib/terminal/electron-sandbox/terminalNativeContribution';
1313
import { ElectronTerminalProfileResolverService } from 'vs/workbench/contrib/terminal/electron-sandbox/terminalProfileResolverService';
1414
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
1515
import { LocalTerminalBackendContribution } from 'vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend';
16+
import { TerminalLogService } from 'vs/platform/terminal/common/terminalLogService';
1617

1718
// Register services
1819
registerMainProcessRemoteService(ILocalPtyService, TerminalIpcChannels.LocalPty);
20+
registerSingleton(ITerminalLogService, TerminalLogService, InstantiationType.Delayed);
1921
registerSingleton(ITerminalProfileResolverService, ElectronTerminalProfileResolverService, InstantiationType.Delayed);
2022

2123
// Register workbench contributions

0 commit comments

Comments
 (0)