mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
Add tracing log level to auth provider, #94005
This commit is contained in:
parent
563997c6de
commit
bf456b64ab
|
@ -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",
|
||||
|
|
|
@ -45,6 +45,7 @@ export class Keychain {
|
|||
|
||||
async setToken(token: string): Promise<void> {
|
||||
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<string | null | undefined> {
|
||||
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}`);
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue