Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide output channel unless used #55

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/plugin/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export enum Verbosity {
debug = 4
}

export class Logger {
public static instance = new Logger();

protected outputChannel = vscode.window.createOutputChannel(manifest.DISPLAY_NAME);
export abstract class Logger {
protected logVerbosity: Verbosity;

protected constructor() {
Expand All @@ -45,6 +42,8 @@ export class Logger {
return Verbosity[config as keyof typeof Verbosity];
}

protected abstract logMessage(message: string): void;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public log(verbosity: Verbosity, ...messages: Array<string | any>): void {
if (this.logVerbosity === Verbosity.off || verbosity > this.logVerbosity) {
Expand All @@ -53,7 +52,7 @@ export class Logger {

const result = messages.map(message => typeof message === 'string' ? message : JSON.stringify(message, undefined, '\t')).join(' ');

this.outputChannel.appendLine(result);
this.logMessage(result);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -66,4 +65,17 @@ export class Logger {
public debug = (...messages: Array<string | any>): void => this.log(Verbosity.debug, ...messages);
}

export const outputChannelLogger = Logger.instance;
class OutputChannelLogger extends Logger {
public static instance = new OutputChannelLogger();

protected outputChannel: vscode.OutputChannel | undefined;

protected override logMessage(message: string): void {
if (!this.outputChannel) {
this.outputChannel = vscode.window.createOutputChannel(manifest.DISPLAY_NAME);
}
this.outputChannel.appendLine(message);
}
}

export const outputChannelLogger = OutputChannelLogger.instance;