-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.ts
55 lines (44 loc) · 1.44 KB
/
log.ts
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
// adapted from rust-analyzer /editors/code/src/util.ts
import { inspect } from 'util';
import * as vscode from 'vscode';
const clientLog = new (class {
private enabled = true;
private readonly output = vscode.window.createOutputChannel("Fe Analyzer Client");
setEnabled(yes: boolean): void {
clientLog.enabled = yes;
}
// Hint: the type [T, ...T[]] means a non-empty array
debug(...msg: [unknown, ...unknown[]]): void {
if (!clientLog.enabled) return;
clientLog.write("DEBUG", ...msg);
}
info(...msg: [unknown, ...unknown[]]): void {
clientLog.write("INFO", ...msg);
}
warn(...msg: [unknown, ...unknown[]]): void {
debugger;
clientLog.write("WARN", ...msg);
}
error(...msg: [unknown, ...unknown[]]): void {
debugger;
clientLog.write("ERROR", ...msg);
clientLog.output.show(true);
}
private write(label: string, ...messageParts: unknown[]): void {
const message = messageParts.map(clientLog.stringify).join(" ");
const dateTime = new Date().toLocaleString();
clientLog.output.appendLine(`${label} [${dateTime}]: ${message}`);
}
private stringify(val: unknown): string {
if (typeof val === "string") return val;
return inspect(val, {
colors: false,
depth: 6, // heuristic
});
}
})();
const serverOutputChannel = vscode.window.createOutputChannel("Fe Analyzer Server");
export {
clientLog,
serverOutputChannel,
};