MCPcopy
hub / github.com/PowerShell/vscode-powershell / Logger

Class Logger

src/logging.ts:36–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36export class Logger implements ILogger {
37 // Log output channel handles all the verbosity management so we don't have to.
38 private logChannel: LogOutputChannel;
39 public get logLevel(): LogLevel {
40 return this.logChannel.logLevel;
41 }
42
43 constructor(logChannel?: LogOutputChannel) {
44 this.logChannel =
45 logChannel ??
46 window.createOutputChannel("PowerShell", { log: true });
47 }
48
49 public dispose(): void {
50 this.logChannel.dispose();
51 }
52
53 private writeAtLevel(
54 logLevel: LogLevel,
55 message: string,
56 ...additionalMessages: string[]
57 ): void {
58 if (logLevel >= this.logLevel) {
59 void this.writeLine(message, logLevel);
60
61 for (const additionalMessage of additionalMessages) {
62 void this.writeLine(additionalMessage, logLevel);
63 }
64 }
65 }
66
67 public write(message: string, ...additionalMessages: string[]): void {
68 this.writeAtLevel(LogLevel.Info, message, ...additionalMessages);
69 }
70
71 public async writeAndShowInformation(
72 message: string,
73 ...additionalMessages: string[]
74 ): Promise<void> {
75 this.write(message, ...additionalMessages);
76
77 const selection = await window.showInformationMessage(
78 message,
79 "Show Logs",
80 "Okay",
81 );
82 if (selection === "Show Logs") {
83 this.showLogPanel();
84 }
85 }
86
87 public writeTrace(message: string, ...additionalMessages: string[]): void {
88 this.writeAtLevel(LogLevel.Trace, message, ...additionalMessages);
89 }
90
91 public writeDebug(message: string, ...additionalMessages: string[]): void {
92 this.writeAtLevel(LogLevel.Debug, message, ...additionalMessages);
93 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected