forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.ts
More file actions
72 lines (63 loc) · 1.75 KB
/
Copy pathlogger.ts
File metadata and controls
72 lines (63 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import * as vscode from 'vscode';
const enum LogLevel {
Info,
Debug,
Off
}
const SETTINGS_NAMESPACE = 'githubPullRequests';
const LOG_LEVEL_SETTING = 'logLevel';
class Log {
private _outputChannel: vscode.OutputChannel;
private _logLevel: LogLevel;
private _disposable: vscode.Disposable;
constructor() {
this._outputChannel = vscode.window.createOutputChannel('GitHub Pull Request');
this._disposable = vscode.workspace.onDidChangeConfiguration(() => {
this.getLogLevel();
});
this.getLogLevel();
}
public appendLine(message: string, component?: string) {
switch(this._logLevel) {
case LogLevel.Off:
return;
case LogLevel.Debug:
const hrtime = process.hrtime();
const timeStamp = `${hrtime[0]}s ${Math.floor(hrtime[1]/1000000)}ms`;
const info = component ? `${component}> ${message}`: `${message}`;
this._outputChannel.appendLine(`[Debug ${timeStamp}] ${info}`);
return;
case LogLevel.Info:
default:
this._outputChannel.appendLine(`[Info] ` + (component ? `${component}> ${message}`: `${message}`));
return;
}
}
public debug(message: string, component: string) {
if (this._logLevel === LogLevel.Debug) {
this.appendLine(message, component);
}
}
public dispose() {
if (this._disposable) {
this._disposable.dispose();
}
}
private getLogLevel() {
let logLevel = vscode.workspace.getConfiguration(SETTINGS_NAMESPACE).get<string>(LOG_LEVEL_SETTING);
switch(logLevel) {
case 'debug':
this._logLevel = LogLevel.Debug;
break;
case 'off':
this._logLevel = LogLevel.Off;
break;
case 'info':
default:
this._logLevel = LogLevel.Info;
break;
}
}
}
const Logger = new Log();
export default Logger;