Преглед на файлове

Realigns output levels & makes warn the default

Unifies Git channel logging
main
Eric Amodio преди 1 година
родител
ревизия
5f5e4e7822
променени са 5 файла, в които са добавени 74 реда и са изтрити 96 реда
  1. +9
    -7
      package.json
  2. +1
    -1
      src/commands/logging.ts
  3. +10
    -7
      src/config.ts
  4. +30
    -73
      src/env/node/git/git.ts
  5. +24
    -8
      src/extension.ts

+ 9
- 7
package.json Целия файл

@ -4169,18 +4169,20 @@
},
"gitlens.outputLevel": {
"type": "string",
"default": "errors",
"default": "warn",
"enum": [
"silent",
"errors",
"verbose",
"off",
"error",
"warn",
"info",
"debug"
],
"enumDescriptions": [
"Logs nothing",
"Logs only errors",
"Logs all errors, warnings, and messages",
"Logs all errors, warnings, and messages with extra context useful for debugging"
"Logs errors and warnings",
"Logs errors, warnings, and messages",
"Logs verbose errors, warnings, and messages. Best for issue reporting."
],
"markdownDescription": "Specifies how much (if any) output will be sent to the GitLens output channel",
"scope": "window",
@ -10481,7 +10483,7 @@
},
{
"command": "gitlens.disableDebugLogging",
"when": "config.gitlens.outputLevel != errors"
"when": "config.gitlens.outputLevel == debug"
},
{
"command": "gitlens.generateCommitMessage",

+ 1
- 1
src/commands/logging.ts Целия файл

@ -22,6 +22,6 @@ export class DisableDebugLoggingCommand extends Command {
}
async execute() {
await configuration.updateEffective('outputLevel', 'errors');
await configuration.updateEffective('outputLevel', 'error');
}
}

+ 10
- 7
src/config.ts Целия файл

@ -263,7 +263,12 @@ export type GraphMinimapMarkersAdditionalTypes = 'localBranches' | 'remoteBranch
export type GravatarDefaultStyle = 'wavatar' | 'identicon' | 'monsterid' | 'mp' | 'retro' | 'robohash';
export type HeatmapLocations = 'gutter' | 'line' | 'overview';
export type KeyMap = 'alternate' | 'chorded' | 'none';
export type OutputLevel = 'silent' | 'errors' | 'verbose' | 'debug';
type DeprecatedOutputLevel =
| /** @deprecated use `off` */ 'silent'
| /** @deprecated use `error` */ 'errors'
| /** @deprecated use `info` */ 'verbose';
export type OutputLevel = LogLevel | DeprecatedOutputLevel;
export const enum StatusBarCommand {
CopyRemoteCommitUrl = 'gitlens.copyRemoteCommitUrl',
@ -767,16 +772,14 @@ export interface ViewsFilesConfig {
readonly threshold: number;
}
export function fromOutputLevel(level: LogLevel | OutputLevel): LogLevel {
export function fromOutputLevel(level: OutputLevel): LogLevel {
switch (level) {
case 'silent':
case /** @deprecated use `off` */ 'silent':
return 'off';
case 'errors':
case /** @deprecated use `error` */ 'errors':
return 'error';
case 'verbose':
case /** @deprecated use `info` */ 'verbose':
return 'info';
case 'debug':
return 'debug';
default:
return level;
}

+ 30
- 73
src/env/node/git/git.ts Целия файл

@ -48,7 +48,6 @@ import { fsExists, isWindows, run, RunError } from './shell';
const emptyArray = Object.freeze([]) as unknown as any[];
const emptyObj = Object.freeze({});
const emptyStr = '';
const gitBranchDefaultConfigs = Object.freeze(['-c', 'color.branch=false']);
const gitDiffDefaultConfigs = Object.freeze(['-c', 'color.diff=false']);
@ -226,32 +225,7 @@ export class Git {
}
} finally {
this.pendingCommands.delete(command);
const duration = getDurationMilliseconds(start);
const slow = duration > slowCallWarningThreshold;
const status =
slow || waiting
? ` (${slow ? `slow${waiting ? ', waiting' : ''}` : ''}${waiting ? 'waiting' : ''})`
: '';
if (exception != null) {
Logger.error(
'',
`[GIT ] ${gitCommand} ${GlyphChars.Dot} ${(exception.message || String(exception) || '')
.trim()
.replace(/fatal: /g, '')
.replace(/\r?\n|\r/g, ` ${GlyphChars.Dot} `)} [${duration}ms]${status}`,
);
} else if (slow) {
Logger.warn(`[GIT ] ${gitCommand} [*${duration}ms]${status}`);
} else {
Logger.log(`[GIT ] ${gitCommand} [${duration}ms]${status}`);
}
this.logGitCommand(
`${gitCommand}${exception != null ? ` ${GlyphChars.Dot} FAILED` : ''}${waiting ? ' (waited)' : ''}`,
duration,
exception,
);
this.logGitCommand(gitCommand, exception, getDurationMilliseconds(start), waiting);
}
}
@ -278,7 +252,7 @@ export class Git {
},
};
const gitCommand = `[${spawnOpts.cwd as string}] git ${args.join(' ')}`;
const gitCommand = `(spawn) [${spawnOpts.cwd as string}] git ${args.join(' ')}`;
// Fixes https://github.com/gitkraken/vscode-gitlens/issues/73 & https://github.com/gitkraken/vscode-gitlens/issues/161
// See https://stackoverflow.com/questions/4144417/how-to-handle-asian-characters-in-file-names-in-git-on-os-x
@ -307,30 +281,7 @@ export class Git {
let exception: Error | undefined;
proc.once('error', e => (exception = e));
proc.once('exit', () => {
const duration = getDurationMilliseconds(start);
const slow = duration > slowCallWarningThreshold;
const status = slow ? ' (slow)' : '';
if (exception != null) {
Logger.error(
'',
`[SGIT ] ${gitCommand} ${GlyphChars.Dot} ${(exception.message || String(exception) || '')
.trim()
.replace(/fatal: /g, '')
.replace(/\r?\n|\r/g, ` ${GlyphChars.Dot} `)} [${duration}ms]${status}`,
);
} else if (slow) {
Logger.warn(`[SGIT ] ${gitCommand} [*${duration}ms]${status}`);
} else {
Logger.log(`[SGIT ] ${gitCommand} [${duration}ms]${status}`);
}
this.logGitCommand(
`${gitCommand}${exception != null ? ` ${GlyphChars.Dot} FAILED` : ''}`,
duration,
exception,
);
});
proc.once('exit', () => this.logGitCommand(gitCommand, exception, getDurationMilliseconds(start), false));
return proc;
}
@ -2268,7 +2219,7 @@ export class Git {
}
Logger.log(scope, `\u2022 '${text}'`);
this.logGitCommand(`[TERM] ${text}`, 0);
this.logCore(`[TERM] ${text}`);
const terminal = ensureGitTerminal();
terminal.show(false);
@ -2278,31 +2229,37 @@ export class Git {
terminal.sendText(text, options?.execute ?? false);
}
private _gitOutput: OutputChannel | undefined;
private logGitCommand(command: string, ex: Error | undefined, duration: number, waiting: boolean): void {
const slow = duration > slowCallWarningThreshold;
const status = slow && waiting ? ' (slow, waiting)' : waiting ? ' (waiting)' : slow ? ' (slow)' : '';
if (ex != null) {
Logger.error(
'',
`[GIT ] ${command} ${GlyphChars.Dot} ${(ex.message || String(ex) || '')
.trim()
.replace(/fatal: /g, '')
.replace(/\r?\n|\r/g, ` ${GlyphChars.Dot} `)} [${duration}ms]${status}`,
);
} else if (slow) {
Logger.warn(`[GIT ] ${command} [*${duration}ms]${status}`);
} else {
Logger.log(`[GIT ] ${command} [${duration}ms]${status}`);
}
private logGitCommand(command: string, duration: number, ex?: Error): void {
if (!Logger.enabled('debug') && !Logger.isDebugging) return;
this.logCore(`[${slow ? '*' : ' '}${duration.toString().padStart(6)}ms] ${command}${status}`, ex);
}
const slow = duration > slowCallWarningThreshold;
private _gitOutput: OutputChannel | undefined;
if (Logger.isDebugging) {
if (ex != null) {
console.error(Logger.timestamp, '[GitLens (Git)]', command ?? emptyStr, ex);
} else if (slow) {
console.warn(Logger.timestamp, '[GitLens (Git)]', command ?? emptyStr);
} else {
console.log(Logger.timestamp, '[GitLens (Git)]', command ?? emptyStr);
}
}
private logCore(message: string, ex?: Error | undefined): void {
if (!Logger.enabled(ex != null ? 'error' : 'debug')) return;
if (this._gitOutput == null) {
this._gitOutput = window.createOutputChannel('GitLens (Git)');
this._gitOutput ??= window.createOutputChannel('GitLens (Git)');
this._gitOutput.appendLine(`${Logger.timestamp} ${message}${ex != null ? ` ${GlyphChars.Dot} FAILED` : ''}`);
if (ex != null) {
this._gitOutput.appendLine(`\n${String(ex)}\n`);
}
this._gitOutput.appendLine(
`${Logger.timestamp} [${slow ? '*' : ' '}${duration.toString().padStart(6)}ms] ${command}${
ex != null ? `\n\n${ex.toString()}` : emptyStr
}`,
);
}
}

+ 24
- 8
src/extension.ts Целия файл

@ -33,12 +33,30 @@ export async function activate(context: ExtensionContext): Promise
const gitlensVersion: string = context.extension.packageJSON.version;
const prerelease = satisfies(gitlensVersion, '> 2020.0.0');
const outputLevel = configuration.get('outputLevel');
const defaultDateLocale = configuration.get('defaultDateLocale');
const logLevel = fromOutputLevel(configuration.get('outputLevel'));
Logger.configure(
{
name: 'GitLens',
createChannel: function (name: string) {
return window.createOutputChannel(name);
const channel = window.createOutputChannel(name);
context.subscriptions.push(channel);
if (logLevel === 'error' || logLevel === 'warn') {
channel.appendLine(
`GitLens${prerelease ? ' (pre-release)' : ''} v${gitlensVersion} activating in ${
env.appName
} (${codeVersion}) on the ${isWeb ? 'web' : 'desktop'}; language='${
env.language
}', logLevel='${logLevel}', defaultDateLocale='${defaultDateLocale}' (${env.machineId}|${
env.sessionId
})`,
);
channel.appendLine(
'To enable debug logging, set `"gitlens.outputLevel: "debug"` or run "GitLens: Enable Debug Logging" from the Command Palette',
);
}
return channel;
},
toLoggable: function (o: any) {
if (isGitUri(o)) {
@ -59,17 +77,15 @@ export async function activate(context: ExtensionContext): Promise
return undefined;
},
},
fromOutputLevel(outputLevel),
logLevel,
context.extensionMode === ExtensionMode.Development,
);
const defaultDateLocale = configuration.get('defaultDateLocale');
const sw = new Stopwatch(`GitLens${prerelease ? ' (pre-release)' : ''} v${gitlensVersion}`, {
log: {
message: ` activating in ${env.appName} (${codeVersion}) on the ${isWeb ? 'web' : 'desktop'}; language='${
env.language
}', defaultDateLocale='${defaultDateLocale}' (${env.machineId}|${env.sessionId})`,
}', logLevel='${logLevel}', defaultDateLocale='${defaultDateLocale}' (${env.machineId}|${env.sessionId})`,
//${context.extensionRuntime !== ExtensionRuntime.Node ? ' in a webworker' : ''}
},
});
@ -160,9 +176,9 @@ export async function activate(context: ExtensionContext): Promise
void storage.store(prerelease ? 'synced:preVersion' : 'synced:version', gitlensVersion);
}
if (outputLevel === 'debug') {
if (logLevel === 'debug') {
setTimeout(async () => {
if (configuration.get('outputLevel') !== 'debug') return;
if (fromOutputLevel(configuration.get('outputLevel')) !== 'debug') return;
if (!container.prereleaseOrDebugging) {
if (await showDebugLoggingWarningMessage()) {

Зареждане…
Отказ
Запис