-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathlogger.ts
More file actions
52 lines (41 loc) · 1.24 KB
/
logger.ts
File metadata and controls
52 lines (41 loc) · 1.24 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
import * as vscode from 'vscode';
class Logger {
private static outputChannel: vscode.OutputChannel;
static initialize() {
this.outputChannel = vscode.window.createOutputChannel('AI Commit');
}
static info(message: string, ...args: any[]) {
this.log('INFO', message, ...args);
}
static warn(message: string, ...args: any[]) {
this.log('WARN', message, ...args);
}
static error(message: string, ...args: any[]) {
this.log('ERROR', message, ...args);
}
private static log(level: string, message: string, ...args: any[]) {
const timestamp = new Date().toISOString();
const formattedMessage = `[${timestamp}] [${level}] ${message}`;
if (args.length > 0) {
this.outputChannel.appendLine(`${formattedMessage} ${args.map(a => this.formatArg(a)).join(' ')}`);
} else {
this.outputChannel.appendLine(formattedMessage);
}
}
private static formatArg(a: any): string {
if (a instanceof Error) {
return `${a.message}\n${a.stack || ''}`;
}
if (typeof a === 'object') {
return JSON.stringify(a, null, 2);
}
return String(a);
}
static show() {
this.outputChannel?.show(true);
}
static dispose() {
this.outputChannel?.dispose();
}
}
export { Logger };