Repository navigation
Expand file tree
/
Copy pathlogger.ts
More file actions
51 lines (41 loc) · 1.5 KB
/
Copy pathlogger.ts
File metadata and controls
51 lines (41 loc) · 1.5 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
import { OutputChannel, window } from 'vscode';
import { SystemSettings } from './models/configurationSettings';
import { LogLevel } from './models/logLevel';
class Log {
private readonly _outputChannel: OutputChannel;
private readonly _restClientSettings: SystemSettings = SystemSettings.Instance;
public constructor() {
this._outputChannel = window.createOutputChannel('REST');
}
public verbose(message: string, data?: any): void {
this.log(LogLevel.Verbose, message, data);
}
public info(message: string, data?: any): void {
this.log(LogLevel.Info, message, data);
}
public warn(message: string, data?: any): void {
this.log(LogLevel.Warn, message, data);
}
public error(message: string, data?: any): void {
this.log(LogLevel.Error, message, data);
}
public log(level: LogLevel, message: string, data?: any): void {
if (level >= this._restClientSettings.logLevel) {
this._outputChannel.appendLine(`[${LogLevel[level]} - ${(new Date().toLocaleTimeString())}] ${message}`);
if (data) {
this._outputChannel.appendLine(this.data2String(data));
}
}
}
private data2String(data: any): string {
if (data instanceof Error) {
return data.stack || data.message;
}
if (typeof data === 'string') {
return data;
}
return JSON.stringify(data, null, 2);
}
}
const Logger = new Log();
export default Logger;