Skip to content

Commit 77dc337

Browse files
committed
refactor: directly use a LogOutputChannel
OutputChannelLogger was implemented before LogOutputChannel existed, so modernize and use it
1 parent 02bb4c3 commit 77dc337

File tree

1 file changed

+3
-52
lines changed

1 file changed

+3
-52
lines changed

src/logging.ts

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,6 @@ import * as vscode from "vscode";
22

33
import { outputChannelName } from "./constants";
44

5-
export interface ILogger {
6-
debug(message: string): void;
7-
error(message: string): void;
8-
info(message: string): void;
9-
error(errOrMessage: Error | string): void;
10-
}
11-
12-
export class OutputChannelLogger extends vscode.Disposable implements ILogger {
13-
private _outputChannel: vscode.OutputChannel;
14-
15-
constructor(channelName: string) {
16-
const outputChannel = vscode.window.createOutputChannel(channelName);
17-
18-
super(() => {
19-
outputChannel.dispose();
20-
});
21-
22-
this._outputChannel = outputChannel;
23-
}
24-
25-
protected _logMessage(prefix: string, message: string) {
26-
// Match the timestamp format used by VS Code's built-in log
27-
const timestamp = new Date()
28-
.toISOString()
29-
.match(/^(.*)T(.*)Z$/)!
30-
.slice(1, 3)
31-
.join(" ");
32-
33-
this._outputChannel.appendLine(`[${timestamp}] [${prefix}] ${message}`);
34-
}
35-
36-
debug(message: string): void {
37-
this._logMessage("debug", message);
38-
}
39-
40-
error(errOrMessage: Error | string): void {
41-
this._logMessage(
42-
"error",
43-
errOrMessage instanceof Error ? errOrMessage.message : errOrMessage,
44-
);
45-
}
46-
47-
info(message: string): void {
48-
this._logMessage("info", message);
49-
}
50-
51-
warn(message: string): void {
52-
this._logMessage("warn", message);
53-
}
54-
}
55-
56-
export default new OutputChannelLogger(outputChannelName);
5+
export default vscode.window.createOutputChannel(outputChannelName, {
6+
log: true,
7+
});

0 commit comments

Comments
 (0)