💄 merge notebook rendering log channel. (#172877)

This commit is contained in:
Peng Lyu 2023-01-30 17:00:18 -08:00 committed by GitHub
parent 10ffbae8ae
commit b8ef25af1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 68 deletions

View file

@ -66,7 +66,7 @@ class NotebookKernelDetection extends Disposable implements IWorkbenchContributi
});
if (shouldStartDetection && !this._detectionMap.has(notebookType)) {
this._notebookLoggingService.log('KernelDetection', `start extension activation for ${notebookType}`);
this._notebookLoggingService.debug('KernelDetection', `start extension activation for ${notebookType}`);
const task = this._notebookKernelService.registerNotebookKernelDetectionTask({
notebookType: notebookType
});
@ -88,7 +88,7 @@ class NotebookKernelDetection extends Disposable implements IWorkbenchContributi
const taskToDelete: string[] = [];
for (const [notebookType, task] of this._detectionMap) {
if (this._extensionService.activationEventIsDone(`onNotebook:${notebookType}`)) {
this._notebookLoggingService.log('KernelDetection', `finish extension activation for ${notebookType}`);
this._notebookLoggingService.debug('KernelDetection', `finish extension activation for ${notebookType}`);
taskToDelete.push(notebookType);
task.dispose();
}

View file

@ -892,12 +892,6 @@ configurationRegistry.registerConfiguration({
type: 'boolean',
tags: ['notebookLayout'],
default: false
},
[NotebookSetting.logging]: {
markdownDescription: nls.localize('notebook.logging', "Enable logging for notebook support."),
type: 'boolean',
tags: ['notebookLayout'],
default: false
}
}
});

View file

@ -1499,15 +1499,15 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
private async _warmupWithMarkdownRenderer(viewModel: NotebookViewModel, viewState: INotebookEditorViewState | undefined) {
this.logService.log('NotebookEditorWidget', 'warmup ' + this.viewModel?.uri.toString());
this.logService.debug('NotebookEditorWidget', 'warmup ' + this.viewModel?.uri.toString());
await this._resolveWebview();
this.logService.log('NotebookEditorWidget', 'warmup - webview resolved');
this.logService.debug('NotebookEditorWidget', 'warmup - webview resolved');
// make sure that the webview is not visible otherwise users will see pre-rendered markdown cells in wrong position as the list view doesn't have a correct `top` offset yet
this._webview!.element.style.visibility = 'hidden';
// warm up can take around 200ms to load markdown libraries, etc.
await this._warmupViewport(viewModel, viewState);
this.logService.log('NotebookEditorWidget', 'warmup - viewport warmed up');
this.logService.debug('NotebookEditorWidget', 'warmup - viewport warmed up');
// todo@rebornix @mjbvz, is this too complicated?
@ -1526,7 +1526,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
this._list.scrollTop = viewState?.scrollPosition?.top ?? 0;
this._debug('finish initial viewport warmup and view state restore.');
this._webview!.element.style.visibility = 'visible';
this.logService.log('NotebookEditorWidget', 'warmup - list view model attached, set to visible');
this.logService.debug('NotebookEditorWidget', 'warmup - list view model attached, set to visible');
}
private async _warmupViewport(viewModel: NotebookViewModel, viewState: INotebookEditorViewState | undefined) {

View file

@ -44,10 +44,10 @@ export class NotebookKernelHistoryService extends Disposable implements INoteboo
const selectedKernel = allAvailableKernels.selected;
// We will suggest the only kernel
const suggested = allAvailableKernels.all.length === 1 ? allAvailableKernels.all[0] : undefined;
this._notebookLoggingService.log('History', `getMatchingKernels: ${allAvailableKernels.all.length} kernels available for ${notebook.uri.path}. Selected: ${allAvailableKernels.selected?.label}. Suggested: ${suggested?.label}`);
this._notebookLoggingService.debug('History', `getMatchingKernels: ${allAvailableKernels.all.length} kernels available for ${notebook.uri.path}. Selected: ${allAvailableKernels.selected?.label}. Suggested: ${suggested?.label}`);
const mostRecentKernelIds = this._mostRecentKernelsMap[notebook.viewType] ? [...this._mostRecentKernelsMap[notebook.viewType].values()] : [];
const all = mostRecentKernelIds.map(kernelId => allKernels.find(kernel => kernel.id === kernelId)).filter(kernel => !!kernel) as INotebookKernel[];
this._notebookLoggingService.log('History', `mru: ${mostRecentKernelIds.length} kernels in history, ${all.length} registered already.`);
this._notebookLoggingService.debug('History', `mru: ${mostRecentKernelIds.length} kernels in history, ${all.length} registered already.`);
return {
selected: selectedKernel ?? suggested,

View file

@ -6,62 +6,34 @@
import * as nls from 'vs/nls';
import { Disposable } from 'vs/base/common/lifecycle';
import { INotebookLoggingService } from 'vs/workbench/contrib/notebook/common/notebookLoggingService';
import { Registry } from 'vs/platform/registry/common/platform';
import { IOutputChannelRegistry, IOutputService, Extensions as OutputExt, IOutputChannel } from 'vs/workbench/services/output/common/output';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogger, ILoggerService } from 'vs/platform/log/common/log';
import { joinPath } from 'vs/base/common/resources';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
const logChannelId = 'notebook.rendering';
export class NotebookLoggingService extends Disposable implements INotebookLoggingService {
_serviceBrand: undefined;
static ID: string = 'notebook';
private _enabled: boolean = false;
private _outputChannel: IOutputChannel | undefined = undefined;
private readonly _logger: ILogger;
constructor(
@IOutputService private readonly _outputService: IOutputService,
@IConfigurationService private readonly _configurationService: IConfigurationService
@ILoggerService loggerService: ILoggerService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
) {
super();
this._enabled = this._configurationService.getValue<boolean>('notebook.logging');
this._register(this._configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('notebook.logging')) {
this._enabled = this._configurationService.getValue<boolean>('notebook.logging');
}
}));
const logsPath = joinPath(environmentService.windowLogsPath, 'notebook.rendering.log');
this._logger = this._register(loggerService.createLogger(logsPath, { id: logChannelId, name: nls.localize('renderChannelName', "Notebook rendering") }));
}
private _getOrCreateOutputChannel(): IOutputChannel {
if (this._outputChannel) {
return this._outputChannel;
}
const channel = this._outputService.getChannel(NotebookLoggingService.ID);
if (channel) {
this._outputChannel = channel;
return channel;
}
const outputChannelRegistry = Registry.as<IOutputChannelRegistry>(OutputExt.OutputChannels);
outputChannelRegistry.registerChannel({ id: NotebookLoggingService.ID, label: nls.localize('notebook.log', "Notebooks"), log: false });
this._outputChannel = this._outputService.getChannel(NotebookLoggingService.ID);
if (!this._outputChannel) {
throw new Error('output channel not found');
}
return this._outputChannel;
debug(category: string, output: string): void {
this._logger.debug(`[${category}] ${output}`);
}
log(category: string, output: string): void {
if (!this._enabled) {
return;
}
const channel = this._getOrCreateOutputChannel();
channel.append(`[${category}] ${output}\n`);
info(category: string, output: string): void {
this._logger.info(`[${category}] ${output}`);
}
}

View file

@ -27,7 +27,6 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IFileService } from 'vs/platform/files/common/files';
import { ILogger, ILoggerService, ILogService } from 'vs/platform/log/common/log';
import { IOpenerService, matchesScheme, matchesSomeScheme } from 'vs/platform/opener/common/opener';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { editorFindMatch, editorFindMatchHighlight } from 'vs/platform/theme/common/colorRegistry';
@ -52,6 +51,7 @@ import { FromWebviewMessage, IAckOutputHeight, IClickedDataUrlMessage, ICodeBloc
import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { INotebookLoggingService } from 'vs/workbench/contrib/notebook/common/notebookLoggingService';
const LINE_COLUMN_REGEX = /:([\d]+)(?::([\d]+))?$/;
const LineQueryRegex = /line=(\d+)/;
@ -110,7 +110,6 @@ interface BacklayerWebviewOptions {
readonly outputLineLimit: number;
}
const logChannelId = 'notebook.rendering';
export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
@ -139,8 +138,6 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
private firstInit = true;
private initializeMarkupPromise?: { readonly requestId: string; readonly p: DeferredPromise<void>; readonly isFirstInit: boolean };
private readonly _renderLogger: ILogger;
private readonly nonce = UUID.generateUuid();
constructor(
@ -166,15 +163,11 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
@IStorageService private readonly storageService: IStorageService,
@IPathService private readonly pathService: IPathService,
@ILoggerService loggerService: ILoggerService,
@ILogService logService: ILogService,
@INotebookLoggingService private readonly notebookLogService: INotebookLoggingService,
@IThemeService themeService: IThemeService,
) {
super(themeService);
const logsPath = joinPath(environmentService.windowLogsPath, 'notebook.rendering.log');
this._renderLogger = this._register(loggerService.createLogger(logsPath, { id: logChannelId, name: nls.localize('renderChannelName', "Notebook rendering") }));
this._logRendererDebugMessage('Creating backlayer webview for notebook');
this.element = document.createElement('div');
@ -222,7 +215,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
}
private _logRendererDebugMessage(msg: string) {
this._renderLogger.debug(`${this.documentUri} (${this.id}) - ${msg}`);
this.notebookLogService.debug('BacklayerWebview', `${this.documentUri} (${this.id}) - ${msg}`);
}
private _updateStyles() {

View file

@ -9,5 +9,6 @@ export const INotebookLoggingService = createDecorator<INotebookLoggingService>(
export interface INotebookLoggingService {
readonly _serviceBrand: undefined;
log(category: string, output: string): void;
info(category: string, output: string): void;
debug(category: string, output: string): void;
}

View file

@ -86,7 +86,8 @@ suite('NotebookKernelHistoryService', () => {
});
instantiationService.stub(INotebookLoggingService, new class extends mock<INotebookLoggingService>() {
override log() { }
override info() { }
override debug() { }
});
const kernelHistoryService = instantiationService.createInstance(NotebookKernelHistoryService);
@ -136,7 +137,8 @@ suite('NotebookKernelHistoryService', () => {
});
instantiationService.stub(INotebookLoggingService, new class extends mock<INotebookLoggingService>() {
override log() { }
override info() { }
override debug() { }
});
const kernelHistoryService = instantiationService.createInstance(NotebookKernelHistoryService);