From 5004c20bce895d88497a308d5f32710b91951f78 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 22 Jan 2022 01:30:51 -0500 Subject: [PATCH] Improves git command logging --- src/env/node/git/git.ts | 19 +++++++++++-------- src/logger.ts | 10 ++++++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/env/node/git/git.ts b/src/env/node/git/git.ts index b7e38e7..83730bf 100644 --- a/src/env/node/git/git.ts +++ b/src/env/node/git/git.ts @@ -113,7 +113,7 @@ export async function git(options: GitCommandOptio pendingCommands.set(command, promise); } else { waiting = true; - Logger.debug(`${gitCommand} ${GlyphChars.Dot} waiting...`); + Logger.debug(`[GIT ] ${gitCommand} ${GlyphChars.Dot} waiting...`); } let exception: Error | undefined; @@ -140,22 +140,25 @@ export async function git(options: GitCommandOptio pendingCommands.delete(command); const duration = Strings.getDurationMilliseconds(start); - const elapsed = `${duration} ms ${waiting ? '(waited) ' : ''}`; + const slow = duration > Logger.slowCallWarningThreshold; + const status = + slow || waiting ? ` (${slow ? `slow${waiting ? ', waiting' : ''}` : ''}${waiting ? 'waiting' : ''})` : ''; + if (exception != null) { Logger.error( '', - `[${runOpts.cwd}] Git ${(exception.message || exception.toString() || '') + `[GIT ] [${runOpts.cwd}] git ${(exception.message || exception.toString() || '') .trim() .replace(/fatal: /g, '') - .replace(/\r?\n|\r/g, ` ${GlyphChars.Dot} `)} ${GlyphChars.Dot} ${elapsed}`, + .replace(/\r?\n|\r/g, ` ${GlyphChars.Dot} `)} ${GlyphChars.Dot} ${duration} ms${status}`, ); - } else if (duration > Logger.slowCallWarningThreshold) { - Logger.warn(`${gitCommand} ${GlyphChars.Dot} ${elapsed} (slow)`); + } else if (slow) { + Logger.warn(`[GIT ] ${gitCommand} ${GlyphChars.Dot} ${duration} ms${status}`); } else { - Logger.log(`${gitCommand} ${GlyphChars.Dot} ${elapsed}`); + Logger.log(`[GIT ] ${gitCommand} ${GlyphChars.Dot} ${duration} ms${status}`); } Logger.logGitCommand( - `${gitCommand} ${GlyphChars.Dot} ${exception !== undefined ? 'FAILED ' : ''}${elapsed}`, + `${gitCommand}${exception != null ? ` ${GlyphChars.Dot} FAILED` : ''}${waiting ? ' (waited)' : ''}`, duration, exception, ); diff --git a/src/logger.ts b/src/logger.ts index 17a7903..d8e7e1d 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -244,10 +244,12 @@ export class Logger { static logGitCommand(command: string, duration: number, ex?: Error): void { if (this.level < OrderedLevel.Debug && !this.isDebugging) return; + const slow = duration > Logger.slowCallWarningThreshold; + if (this.isDebugging) { if (ex != null) { console.error(this.timestamp, gitConsolePrefix, command ?? emptyStr, ex); - } else if (duration > Logger.slowCallWarningThreshold) { + } else if (slow) { console.warn(this.timestamp, gitConsolePrefix, command ?? emptyStr); } else { console.log(this.timestamp, gitConsolePrefix, command ?? emptyStr); @@ -257,7 +259,11 @@ export class Logger { if (this.gitOutput == null) { this.gitOutput = window.createOutputChannel(gitOutputChannelName); } - this.gitOutput.appendLine(`${this.timestamp} ${command}${ex != null ? `\n\n${ex.toString()}` : emptyStr}`); + this.gitOutput.appendLine( + `${this.timestamp} [${slow ? '*' : ' '}${duration.toString().padStart(6)}ms] ${command}${ + ex != null ? `\n\n${ex.toString()}` : emptyStr + }`, + ); } }