Browse Source

Improves git command logging

main
Eric Amodio 3 years ago
parent
commit
5004c20bce
2 changed files with 19 additions and 10 deletions
  1. +11
    -8
      src/env/node/git/git.ts
  2. +8
    -2
      src/logger.ts

+ 11
- 8
src/env/node/git/git.ts View File

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

+ 8
- 2
src/logger.ts View File

@ -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
}`,
);
}
}

Loading…
Cancel
Save