Git log level polish (#151095)

This commit is contained in:
Ladislau Szomoru
2022-06-02 15:10:18 +02:00
committed by GitHub
parent 5103c931a0
commit 4bd12af7f6
3 changed files with 29 additions and 28 deletions

View File

@@ -368,7 +368,7 @@ export class CommandCenter {
return;
}
this.outputChannelLogger.setLogLevel(choice.logLevel);
this.outputChannelLogger.currentLogLevel = choice.logLevel;
}
@command('git.refresh', { repository: true })

View File

@@ -30,12 +30,22 @@ export class OutputChannelLogger {
private _onDidChangeLogLevel = new EventEmitter<LogLevel>();
readonly onDidChangeLogLevel: Event<LogLevel> = 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();
}

View File

@@ -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)));