提交 0b0577ea 编写于 作者: S Sandeep Somavarapu

browse session logs

上级 df8220e0
......@@ -8,7 +8,7 @@ import { join } from 'vs/base/common/path';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actions';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { SetLogLevelAction, OpenLogsFolderAction } from 'vs/workbench/contrib/logs/common/logsActions';
import { SetLogLevelAction, OpenLogsFolderAction, OpenSessionLogFileAction } from 'vs/workbench/contrib/logs/common/logsActions';
import * as Constants from 'vs/workbench/contrib/logs/common/logConstants';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
......@@ -46,6 +46,10 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
private registerWebContributions(): void {
Registry.as<IOutputChannelRegistry>(OutputExt.OutputChannels).registerChannel({ id: Constants.rendererLogChannelId, label: nls.localize('rendererLog', "Window"), file: this.environmentService.logFile, log: true });
this.instantiationService.createInstance(LogsDataCleaner);
const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions);
const devCategory = nls.localize('developer', "Developer");
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(OpenSessionLogFileAction, OpenSessionLogFileAction.ID, OpenSessionLogFileAction.LABEL), 'Developer: Open Log File (Session)...', devCategory);
}
private registerNativeContributions(): void {
......
......@@ -9,8 +9,13 @@ import { join } from 'vs/base/common/path';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IWindowsService } from 'vs/platform/windows/common/windows';
import { ILogService, LogLevel, DEFAULT_LOG_LEVEL } from 'vs/platform/log/common/log';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { URI } from 'vs/base/common/uri';
import { IFileService } from 'vs/platform/files/common/files';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { dirname, basename, isEqual } from 'vs/base/common/resources';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { startsWith } from 'vs/base/common/strings';
export class OpenLogsFolderAction extends Action {
......@@ -73,3 +78,68 @@ export class SetLogLevelAction extends Action {
return undefined;
}
}
export class OpenSessionLogFileAction extends Action {
static ID = 'workbench.action.openSessionLogFile';
static LABEL = nls.localize('openSessionLogFile', "Open Log File (Session)...");
constructor(id: string, label: string,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IFileService private readonly fileService: IFileService,
@IQuickInputService private readonly quickInputService: IQuickInputService,
@IEditorService private readonly editorService: IEditorService,
) {
super(id, label);
}
async run(): Promise<void> {
const sessionResult = await this.quickInputService.pick(
this.getSessions().then(sessions => sessions.map((s, index) => (<IQuickPickItem>{
id: s.toString(),
label: basename(s),
description: index === 0 ? nls.localize('current', "Current") : undefined
}))),
{
canPickMany: false,
placeHolder: nls.localize('sessions placeholder', "Select Session")
});
if (sessionResult) {
const logFileResult = await this.quickInputService.pick(
this.getLogFiles(URI.parse(sessionResult.id!)).then(logFiles => logFiles.map(s => (<IQuickPickItem>{
id: s.toString(),
label: startsWith(basename(s), 'window') ? nls.localize('window', "Window") : basename(s)
}))),
{
canPickMany: false,
placeHolder: nls.localize('log placeholder', "Select Log file")
});
if (logFileResult) {
return this.editorService.openEditor({ resource: URI.parse(logFileResult.id!) }).then(() => undefined);
}
}
}
private async getSessions(): Promise<URI[]> {
const logsPath = URI.file(this.environmentService.logsPath).with({ scheme: this.environmentService.logFile.scheme });
const result: URI[] = [logsPath];
const stat = await this.fileService.resolve(dirname(logsPath));
if (stat.children) {
result.push(...stat.children
.filter(stat => !isEqual(stat.resource, logsPath) && stat.isDirectory && /^\d{8}T\d{6}$/.test(stat.name))
.sort()
.reverse()
.map(d => d.resource));
}
return result;
}
private async getLogFiles(session: URI): Promise<URI[]> {
const stat = await this.fileService.resolve(session);
if (stat.children) {
return stat.children.filter(stat => !stat.isDirectory).map(stat => stat.resource);
}
return [];
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册