diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index e8cd512b648..32812e42159 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -368,7 +368,7 @@ export class CommandCenter { return; } - this.outputChannelLogger.setLogLevel(choice.logLevel); + this.outputChannelLogger.currentLogLevel = choice.logLevel; } @command('git.refresh', { repository: true }) diff --git a/extensions/git/src/log.ts b/extensions/git/src/log.ts index 570e90c5d85..c0f96ff0216 100644 --- a/extensions/git/src/log.ts +++ b/extensions/git/src/log.ts @@ -30,12 +30,22 @@ export class OutputChannelLogger { private _onDidChangeLogLevel = new EventEmitter(); readonly onDidChangeLogLevel: Event = this._onDidChangeLogLevel.event; - private _currentLogLevel: LogLevel; + private _currentLogLevel!: LogLevel; get currentLogLevel(): LogLevel { return this._currentLogLevel; } + set currentLogLevel(value: LogLevel) { + if (this._currentLogLevel === value) { + return; + } - private _defaultLogLevel: LogLevel; + this._currentLogLevel = value; + this._onDidChangeLogLevel.fire(value); + + this.log(localize('gitLogLevel', "Log level: {0}", LogLevel[value])); + } + + private _defaultLogLevel!: LogLevel; get defaultLogLevel(): LogLevel { return this._defaultLogLevel; } @@ -49,20 +59,26 @@ export class OutputChannelLogger { commands.registerCommand('git.showOutput', () => this.showOutputChannel()); this._disposables.push(this._outputChannel); - // Initialize log level - const config = workspace.getConfiguration('git'); - const logLevel: keyof typeof LogLevel = config.get('logLevel', 'Info'); - this._currentLogLevel = this._defaultLogLevel = LogLevel[logLevel] ?? LogLevel.Info; - - this.logInfo(localize('gitLogLevel', "Log level: {0}", LogLevel[this._currentLogLevel])); + this._disposables.push(workspace.onDidChangeConfiguration(e => { + if (e.affectsConfiguration('git.logLevel')) { + this.onLogLevelChange(); + } + })); + this.onLogLevelChange(); } - private log(message: string, logLevel: LogLevel): void { - if (logLevel < this._currentLogLevel) { + private onLogLevelChange(): void { + const config = workspace.getConfiguration('git'); + const logLevel: keyof typeof LogLevel = config.get('logLevel', 'Info'); + this.currentLogLevel = this._defaultLogLevel = LogLevel[logLevel] ?? LogLevel.Info; + } + + log(message: string, logLevel?: LogLevel): void { + if (logLevel && logLevel < this._currentLogLevel) { return; } - this._outputChannel.appendLine(`[${new Date().toISOString()}] [${LogLevel[logLevel].toLowerCase()}] ${message}`); + this._outputChannel.appendLine(`[${new Date().toISOString()}]${logLevel ? ` [${LogLevel[logLevel].toLowerCase()}]` : ''} ${message}`); } logCritical(message: string): void { @@ -89,21 +105,6 @@ export class OutputChannelLogger { this.log(message, LogLevel.Warning); } - logGitCommand(command: string): void { - this._outputChannel.appendLine(`[${new Date().toISOString()}] ${command}`); - } - - setLogLevel(logLevel: LogLevel): void { - if (this._currentLogLevel === logLevel) { - return; - } - - this._currentLogLevel = logLevel; - this._onDidChangeLogLevel.fire(logLevel); - - this.logInfo(localize('changed', "Log level changed to: {0}", LogLevel[logLevel])); - } - showOutputChannel(): void { this._outputChannel.show(); } diff --git a/extensions/git/src/main.ts b/extensions/git/src/main.ts index ee60d2cb1b1..a5e7c060f00 100644 --- a/extensions/git/src/main.ts +++ b/extensions/git/src/main.ts @@ -90,7 +90,7 @@ async function createModel(context: ExtensionContext, outputChannelLogger: Outpu lines.pop(); } - outputChannelLogger.logGitCommand(lines.join('\n')); + outputChannelLogger.log(lines.join('\n')); }; git.onOutput.addListener('log', onOutput); disposables.push(toDisposable(() => git.onOutput.removeListener('log', onOutput)));