提交 9ec76f9c 编写于 作者: S Sandeep Somavarapu

logs data clean up

上级 77c1e7fa
......@@ -20,6 +20,8 @@ import { ILogService, LogLevel } from 'vs/platform/log/common/log';
import { dirname } from 'vs/base/common/resources';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { isWeb } from 'vs/base/common/platform';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { LogsDataCleaner } from 'vs/workbench/contrib/logs/common/logsDataCleaner';
const workbenchActionsRegistry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionExtensions.WorkbenchActions);
const devCategory = nls.localize('developer', "Developer");
......@@ -30,7 +32,8 @@ class LogOutputChannels extends Disposable implements IWorkbenchContribution {
constructor(
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@ILogService private readonly logService: ILogService,
@IFileService private readonly fileService: IFileService
@IFileService private readonly fileService: IFileService,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super();
if (isWeb) {
......@@ -42,6 +45,7 @@ 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);
}
private registerNativeContributions(): void {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Disposable } from 'vs/base/common/lifecycle';
import { IFileService } from 'vs/platform/files/common/files';
import { basename, dirname } from 'vs/base/common/resources';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { URI } from 'vs/base/common/uri';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
export class LogsDataCleaner extends Disposable {
constructor(
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IFileService private readonly fileService: IFileService,
@ILifecycleService private readonly lifecycleService: ILifecycleService,
) {
super();
this.cleanUpOldLogsSoon();
}
private cleanUpOldLogsSoon(): void {
let handle: NodeJS.Timeout | undefined = setTimeout(async () => {
handle = undefined;
const logsPath = URI.file(this.environmentService.logsPath).with({ scheme: this.environmentService.logFile.scheme });
const stat = await this.fileService.resolve(dirname(logsPath));
if (stat.children) {
const currentLog = basename(logsPath);
const allSessions = stat.children.filter(stat => stat.isDirectory && /^\d{8}T\d{6}$/.test(stat.name));
const oldSessions = allSessions.sort().filter((d, i) => d.name !== currentLog);
const toDelete = oldSessions.slice(0, Math.max(0, oldSessions.length - 49));
Promise.all(toDelete.map(stat => this.fileService.del(stat.resource, { recursive: true })));
}
}, 10 * 1000);
this.lifecycleService.onWillShutdown(() => {
if (handle) {
clearTimeout(handle);
handle = undefined;
}
});
}
}
......@@ -76,7 +76,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
constructor(readonly options: IBrowserWorkbenchEnvironemntConstructionOptions) {
this.args = { _: [] };
this.logsPath = options.logsPath.path;
this.logFile = joinPath(options.logsPath, `window-${generateUuid()}`);
this.logFile = joinPath(options.logsPath, `window-${generateUuid()}.log`);
this.appRoot = '/web/';
this.appNameLong = 'Visual Studio Code - Web';
......
......@@ -9,7 +9,7 @@ import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { VSBuffer } from 'vs/base/common/buffer';
import { FileSystemError } from 'vs/workbench/api/common/extHostTypes';
import { isEqualOrParent, joinPath } from 'vs/base/common/resources';
import { isEqualOrParent, joinPath, relativePath } from 'vs/base/common/resources';
const LOGS_OBJECT_STORE = 'logs';
export const INDEXEDDB_LOG_SCHEME = 'vscode-logs-indexedbd';
......@@ -95,11 +95,14 @@ export class IndexedDBLogProvider extends Disposable implements IFileSystemProvi
request.onerror = () => e(request.error);
request.onsuccess = () => {
const files: [string, FileType][] = [];
const resourceSegments = resource.path.split('/');
for (const key of <string[]>request.result) {
if (isEqualOrParent(URI.file(key).with({ scheme: INDEXEDDB_LOG_SCHEME }), resource, false)) {
const keySegments = key.split('/');
files.push([keySegments[resourceSegments.length], resourceSegments.length + 1 === keySegments.length ? FileType.File : FileType.Directory]);
const keyResource = this.toResource(key);
if (isEqualOrParent(keyResource, resource, false)) {
const path = relativePath(resource, keyResource, false);
if (path) {
const keySegments = path.split('/');
files.push([keySegments[0], keySegments.length === 1 ? FileType.File : FileType.Directory]);
}
}
}
c(files);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册