mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 10:08:49 +01:00
Move logDirectory to ExtensionContext (#45922)
* Move the logDirectory to extensionContext Moves the proposed `logDirectory` to `ExtensionContext` and make it synchronous * Use string for path instead of URI
This commit is contained in:
@@ -5,15 +5,12 @@
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { join } from 'vs/base/common/paths';
|
||||
import { mkdirp, dirExists } from 'vs/base/node/pfs';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { LogLevel } from 'vs/workbench/api/node/extHostTypes';
|
||||
import { ILogService, DelegatedLogService } from 'vs/platform/log/common/log';
|
||||
import { createSpdLogService } from 'vs/platform/log/node/spdlogService';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { memoize } from 'vs/base/common/decorators';
|
||||
import { ExtHostLogServiceShape } from 'vs/workbench/api/node/extHost.protocol';
|
||||
|
||||
|
||||
@@ -42,21 +39,23 @@ export class ExtHostLogService extends DelegatedLogService implements ILogServic
|
||||
return logger;
|
||||
}
|
||||
|
||||
getLogDirectory(extensionID: string): string {
|
||||
return join(this._environmentService.logsPath, `${extensionID}_${this._windowId}`);
|
||||
}
|
||||
|
||||
private createLogger(extensionID: string): ExtHostLogger {
|
||||
const logsDirPath = join(this._environmentService.logsPath, `${extensionID}_${this._windowId}`);
|
||||
const logsDirPath = this.getLogDirectory(extensionID);
|
||||
const logService = createSpdLogService(extensionID, this.getLevel(), logsDirPath);
|
||||
this._register(this.onDidChangeLogLevel(level => logService.setLevel(level)));
|
||||
return new ExtHostLogger(logService, logsDirPath);
|
||||
return new ExtHostLogger(logService);
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtHostLogger implements vscode.Logger {
|
||||
|
||||
constructor(
|
||||
private readonly _logService: ILogService,
|
||||
private readonly _logDirectory: string
|
||||
) {
|
||||
}
|
||||
private readonly _logService: ILogService
|
||||
) { }
|
||||
|
||||
get onDidChangeLogLevel(): Event<LogLevel> {
|
||||
return this._logService.onDidChangeLogLevel;
|
||||
@@ -64,19 +63,6 @@ export class ExtHostLogger implements vscode.Logger {
|
||||
|
||||
get currentLevel(): LogLevel { return this._logService.getLevel(); }
|
||||
|
||||
@memoize
|
||||
get logDirectory(): TPromise<string> {
|
||||
return dirExists(this._logDirectory).then(exists => {
|
||||
if (exists) {
|
||||
return TPromise.wrap(null);
|
||||
} else {
|
||||
return mkdirp(this._logDirectory);
|
||||
}
|
||||
}).then(() => {
|
||||
return this._logDirectory;
|
||||
});
|
||||
}
|
||||
|
||||
trace(message: string, ...args: any[]): void {
|
||||
return this._logService.trace(message, ...args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user