mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
introduce logger service in ext host and use it to create log service
This commit is contained in:
@@ -13,7 +13,7 @@ import { OverviewRulerLane } from 'vs/editor/common/model';
|
||||
import * as languageConfiguration from 'vs/editor/common/modes/languageConfiguration';
|
||||
import { score } from 'vs/editor/common/modes/languageSelector';
|
||||
import * as files from 'vs/platform/files/common/files';
|
||||
import { ExtHostContext, MainContext, ExtHostLogServiceShape, UIKind, CandidatePortSource } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtHostContext, MainContext, UIKind, CandidatePortSource, ExtHostLogLevelServiceShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { ExtHostApiCommands } from 'vs/workbench/api/common/extHostApiCommands';
|
||||
import { ExtHostClipboard } from 'vs/workbench/api/common/extHostClipboard';
|
||||
import { IExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
|
||||
@@ -60,7 +60,7 @@ import { IExtHostDecorations } from 'vs/workbench/api/common/extHostDecorations'
|
||||
import { IExtHostTask } from 'vs/workbench/api/common/extHostTask';
|
||||
import { IExtHostDebugService } from 'vs/workbench/api/common/extHostDebugService';
|
||||
import { IExtHostSearch } from 'vs/workbench/api/common/extHostSearch';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { ILoggerService, ILogService } from 'vs/platform/log/common/log';
|
||||
import { IURITransformerService } from 'vs/workbench/api/common/extHostUriTransformerService';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
|
||||
@@ -113,6 +113,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
const rpcProtocol = accessor.get(IExtHostRpcService);
|
||||
const extHostStorage = accessor.get(IExtHostStorage);
|
||||
const extensionStoragePaths = accessor.get(IExtensionStoragePaths);
|
||||
const extHostLoggerService = accessor.get(ILoggerService);
|
||||
const extHostLogService = accessor.get(ILogService);
|
||||
const extHostTunnelService = accessor.get(IExtHostTunnelService);
|
||||
const extHostApiDeprecation = accessor.get(IExtHostApiDeprecationService);
|
||||
@@ -122,7 +123,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
|
||||
|
||||
// register addressable instances
|
||||
rpcProtocol.set(ExtHostContext.ExtHostFileSystemInfo, extHostFileSystemInfo);
|
||||
rpcProtocol.set(ExtHostContext.ExtHostLogService, <ExtHostLogServiceShape><any>extHostLogService);
|
||||
rpcProtocol.set(ExtHostContext.ExtHostLogLevelServiceShape, <ExtHostLogLevelServiceShape><any>extHostLoggerService);
|
||||
rpcProtocol.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
|
||||
rpcProtocol.set(ExtHostContext.ExtHostConfiguration, extHostConfiguration);
|
||||
rpcProtocol.set(ExtHostContext.ExtHostExtensionService, extensionService);
|
||||
|
||||
@@ -23,7 +23,12 @@ import { IExtHostFileSystemInfo, ExtHostFileSystemInfo } from 'vs/workbench/api/
|
||||
import { IExtHostSecretState, ExtHostSecretState } from 'vs/workbench/api/common/exHostSecretState';
|
||||
import { ExtHostTelemetry, IExtHostTelemetry } from 'vs/workbench/api/common/extHostTelemetry';
|
||||
import { ExtHostEditorTabs, IExtHostEditorTabs } from 'vs/workbench/api/common/extHostEditorTabs';
|
||||
import { ExtHostLoggerService } from 'vs/workbench/api/common/extHostLoggerService';
|
||||
import { ILoggerService, ILogService } from 'vs/platform/log/common/log';
|
||||
import { ExtHostLogService } from 'vs/workbench/api/common/extHostLogService';
|
||||
|
||||
registerSingleton(ILoggerService, ExtHostLoggerService);
|
||||
registerSingleton(ILogService, ExtHostLogService);
|
||||
registerSingleton(IExtHostApiDeprecationService, ExtHostApiDeprecationService);
|
||||
registerSingleton(IExtHostCommands, ExtHostCommands);
|
||||
registerSingleton(IExtHostConfiguration, ExtHostConfiguration);
|
||||
|
||||
@@ -31,7 +31,7 @@ import { ConfigurationScope } from 'vs/platform/configuration/common/configurati
|
||||
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import * as files from 'vs/platform/files/common/files';
|
||||
import { ResourceLabelFormatter } from 'vs/platform/label/common/label';
|
||||
import { LogLevel } from 'vs/platform/log/common/log';
|
||||
import { ILoggerOptions, LogLevel } from 'vs/platform/log/common/log';
|
||||
import { IMarkerData } from 'vs/platform/markers/common/markers';
|
||||
import { IProgressOptions, IProgressStep } from 'vs/platform/progress/common/progress';
|
||||
import * as quickInput from 'vs/platform/quickinput/common/quickInput';
|
||||
@@ -1895,12 +1895,13 @@ export interface ExtHostWindowShape {
|
||||
$onDidChangeWindowFocus(value: boolean): void;
|
||||
}
|
||||
|
||||
export interface ExtHostLogServiceShape {
|
||||
export interface ExtHostLogLevelServiceShape {
|
||||
$setLevel(level: LogLevel): void;
|
||||
}
|
||||
|
||||
export interface MainThreadLogShape {
|
||||
$log(file: UriComponents, level: LogLevel, args: any[]): void;
|
||||
export interface MainThreadLoggerShape {
|
||||
$log(file: UriComponents, messages: [LogLevel, string][]): void;
|
||||
$createLogger(file: UriComponents, options?: ILoggerOptions): Promise<void>;
|
||||
}
|
||||
|
||||
export interface ExtHostOutputServiceShape {
|
||||
@@ -2213,7 +2214,7 @@ export const MainContext = {
|
||||
MainThreadKeytar: createMainId<MainThreadKeytarShape>('MainThreadKeytar'),
|
||||
MainThreadLanguageFeatures: createMainId<MainThreadLanguageFeaturesShape>('MainThreadLanguageFeatures'),
|
||||
MainThreadLanguages: createMainId<MainThreadLanguagesShape>('MainThreadLanguages'),
|
||||
MainThreadLog: createMainId<MainThreadLogShape>('MainThread'),
|
||||
MainThreadLogger: createMainId<MainThreadLoggerShape>('MainThreadLogger'),
|
||||
MainThreadMessageService: createMainId<MainThreadMessageServiceShape>('MainThreadMessageService'),
|
||||
MainThreadOutputService: createMainId<MainThreadOutputServiceShape>('MainThreadOutputService'),
|
||||
MainThreadProgress: createMainId<MainThreadProgressShape>('MainThreadProgress'),
|
||||
@@ -2268,7 +2269,7 @@ export const ExtHostContext = {
|
||||
ExtHostLanguageFeatures: createExtId<ExtHostLanguageFeaturesShape>('ExtHostLanguageFeatures'),
|
||||
ExtHostQuickOpen: createExtId<ExtHostQuickOpenShape>('ExtHostQuickOpen'),
|
||||
ExtHostExtensionService: createExtId<ExtHostExtensionServiceShape>('ExtHostExtensionService'),
|
||||
ExtHostLogService: createExtId<ExtHostLogServiceShape>('ExtHostLogService'),
|
||||
ExtHostLogLevelServiceShape: createExtId<ExtHostLogLevelServiceShape>('ExtHostLogLevelServiceShape'),
|
||||
ExtHostTerminalService: createExtId<ExtHostTerminalServiceShape>('ExtHostTerminalService'),
|
||||
ExtHostSCM: createExtId<ExtHostSCMShape>('ExtHostSCM'),
|
||||
ExtHostSearch: createExtId<ExtHostSearchShape>('ExtHostSearch'),
|
||||
|
||||
20
src/vs/workbench/api/common/extHostLogService.ts
Normal file
20
src/vs/workbench/api/common/extHostLogService.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ILoggerService, LogService } from 'vs/platform/log/common/log';
|
||||
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
|
||||
|
||||
export class ExtHostLogService extends LogService {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
|
||||
constructor(
|
||||
@ILoggerService loggerService: ILoggerService,
|
||||
@IExtHostInitDataService initData: IExtHostInitDataService,
|
||||
) {
|
||||
super(loggerService.createLogger(initData.logFile));
|
||||
}
|
||||
|
||||
}
|
||||
70
src/vs/workbench/api/common/extHostLoggerService.ts
Normal file
70
src/vs/workbench/api/common/extHostLoggerService.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ILogger, ILoggerOptions, AbstractMessageLogger, LogLevel, AbstractLoggerService } from 'vs/platform/log/common/log';
|
||||
import { MainThreadLoggerShape, MainContext, ExtHostLogLevelServiceShape as ExtHostLogLevelServiceShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
|
||||
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
|
||||
export class ExtHostLoggerService extends AbstractLoggerService implements ExtHostLogLevelServiceShape {
|
||||
|
||||
declare readonly _serviceBrand: undefined;
|
||||
private readonly _onDidChangeLogLevel: Emitter<LogLevel>;
|
||||
private readonly _proxy: MainThreadLoggerShape;
|
||||
|
||||
constructor(
|
||||
@IExtHostRpcService rpc: IExtHostRpcService,
|
||||
@IExtHostInitDataService initData: IExtHostInitDataService,
|
||||
) {
|
||||
const emitter = new Emitter<LogLevel>();
|
||||
super(initData.logLevel, emitter.event);
|
||||
this._proxy = rpc.getProxy(MainContext.MainThreadLogger);
|
||||
this._onDidChangeLogLevel = this._register(emitter);
|
||||
}
|
||||
|
||||
$setLevel(level: LogLevel): void {
|
||||
this._onDidChangeLogLevel.fire(level);
|
||||
}
|
||||
|
||||
protected doCreateLogger(resource: URI, logLevel: LogLevel, options?: ILoggerOptions): ILogger {
|
||||
return new Logger(this._proxy, resource, logLevel, options);
|
||||
}
|
||||
}
|
||||
|
||||
class Logger extends AbstractMessageLogger {
|
||||
|
||||
private isLoggerCreated: boolean = false;
|
||||
private buffer: [LogLevel, string][] = [];
|
||||
|
||||
constructor(
|
||||
private readonly proxy: MainThreadLoggerShape,
|
||||
private readonly file: URI,
|
||||
logLevel: LogLevel,
|
||||
loggerOptions?: ILoggerOptions,
|
||||
) {
|
||||
super(loggerOptions?.always);
|
||||
this.setLevel(logLevel);
|
||||
this.proxy.$createLogger(file, loggerOptions)
|
||||
.then(() => {
|
||||
this.doLog(this.buffer);
|
||||
this.isLoggerCreated = true;
|
||||
});
|
||||
}
|
||||
|
||||
protected log(level: LogLevel, message: string) {
|
||||
const messages: [LogLevel, string][] = [[level, message]];
|
||||
if (this.isLoggerCreated) {
|
||||
this.doLog(messages);
|
||||
} else {
|
||||
this.buffer.push(...messages);
|
||||
}
|
||||
}
|
||||
|
||||
private doLog(messages: [LogLevel, string][]) {
|
||||
this.proxy.$log(this.file, messages);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user