Skip to content

Commit

Permalink
Merge pull request #55 from eclipse-cdt-cloud/hide-empty-output
Browse files Browse the repository at this point in the history
Hide output channel unless used
  • Loading branch information
thegecko authored Jan 24, 2024
2 parents f611578 + b3a582f commit 21077df
Showing 1 changed file with 18 additions and 6 deletions.
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;

0 comments on commit 21077df

Please sign in to comment.