diff --git a/extensions/vscode-account/package.json b/extensions/vscode-account/package.json index cd579aef85a1d365375eb5b2d88a11ac6c27c248..3a5407738c8dc72aeaa04acd6c472ef933ccad3b 100644 --- a/extensions/vscode-account/package.json +++ b/extensions/vscode-account/package.json @@ -27,7 +27,20 @@ "title": "%signOut%", "category": "%displayName%" } - ] + ], + "configuration": { + "title": "Microsoft Account", + "properties": { + "microsoftAccount.logLevel": { + "type": "string", + "enum": [ + "info", + "trace" + ], + "default": "info" + } + } + } }, "scripts": { "vscode:prepublish": "npm run compile", diff --git a/extensions/vscode-account/src/keychain.ts b/extensions/vscode-account/src/keychain.ts index a52de4ff64c9148f3fabdd979219e267f29efa08..44d05529cf64aaa1daeccfa5bf393696f37e97bc 100644 --- a/extensions/vscode-account/src/keychain.ts +++ b/extensions/vscode-account/src/keychain.ts @@ -45,6 +45,7 @@ export class Keychain { async setToken(token: string): Promise { try { + Logger.trace('Writing to keychain', token); return await this.keytar.setPassword(SERVICE_ID, ACCOUNT_ID, token); } catch (e) { // Ignore @@ -59,7 +60,9 @@ export class Keychain { async getToken(): Promise { try { - return await this.keytar.getPassword(SERVICE_ID, ACCOUNT_ID); + const result = await this.keytar.getPassword(SERVICE_ID, ACCOUNT_ID); + Logger.trace('Reading from keychain', result); + return result; } catch (e) { // Ignore Logger.error(`Getting token failed: ${e}`); diff --git a/extensions/vscode-account/src/logger.ts b/extensions/vscode-account/src/logger.ts index 7fdbff51432f0b18542612fdb2defc76105143a9..c1bc693e3cb89b97c929aaaa710a48606a01f5dc 100644 --- a/extensions/vscode-account/src/logger.ts +++ b/extensions/vscode-account/src/logger.ts @@ -7,11 +7,23 @@ import * as vscode from 'vscode'; type LogLevel = 'Trace' | 'Info' | 'Error'; +enum Level { + Trace = 'trace', + Info = 'Info' +} + class Log { private output: vscode.OutputChannel; + private level: Level; constructor() { this.output = vscode.window.createOutputChannel('Account'); + this.level = vscode.workspace.getConfiguration('microsoftAccount').get('logLevel') || Level.Info; + vscode.workspace.onDidChangeConfiguration(e => { + if (e.affectsConfiguration('microsoftAccount.logLevel')) { + this.level = vscode.workspace.getConfiguration('microsoftAccount').get('logLevel') || Level.Info; + } + }); } private data2String(data: any): string { @@ -32,6 +44,12 @@ class Log { this.logLevel('Error', message, data); } + public trace(message: string, data?: any): void { + if (this.level === Level.Trace) { + this.logLevel('Trace', message, data); + } + } + public logLevel(level: LogLevel, message: string, data?: any): void { this.output.appendLine(`[${level} - ${this.now()}] ${message}`); if (data) {