diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 6929a36..da55a06 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -905,7 +905,7 @@ export class LocalGitProvider implements GitProvider, Disposable { } } - @log() + @log({ singleLine: true }) resetCaches(...affects: ('branches' | 'contributors' | 'providers' | 'remotes' | 'stashes' | 'status' | 'tags')[]) { if (affects.length === 0 || affects.includes('branches')) { this._branchesCache.clear(); diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index f5faf65..7ad4114 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -960,7 +960,7 @@ export class GitProviderService implements Disposable { return provider.checkout(path, ref, options); } - @log() + @log({ singleLine: true }) resetCaches( ...affects: ('branches' | 'contributors' | 'providers' | 'remotes' | 'stashes' | 'status' | 'tags')[] ): void { diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index 487433c..a54b959 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -819,6 +819,7 @@ export class Repository implements Disposable { this.runTerminalCommand('reset', ...args); } + @log({ singleLine: true }) resetCaches(...affects: ('branches' | 'remotes')[]) { if (affects.length === 0 || affects.includes('branches')) { this._branch = undefined; diff --git a/src/plus/github/githubGitProvider.ts b/src/plus/github/githubGitProvider.ts index 292a459..230fc72 100644 --- a/src/plus/github/githubGitProvider.ts +++ b/src/plus/github/githubGitProvider.ts @@ -365,7 +365,7 @@ export class GitHubGitProvider implements GitProvider, Disposable { _options?: { createBranch?: string } | { path?: string }, ): Promise {} - @log() + @log({ singleLine: true }) resetCaches( ...affects: ('branches' | 'contributors' | 'providers' | 'remotes' | 'stashes' | 'status' | 'tags')[] ): void { diff --git a/src/storage.ts b/src/storage.ts index 54137a3..cf7b93b 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -4,6 +4,7 @@ import { EventEmitter } from 'vscode'; import type { ViewShowBranchComparison } from './config'; import type { StoredSearchQuery } from './git/search'; import type { Subscription } from './subscription'; +import { debug } from './system/decorators/log'; import type { TrackedUsage, TrackedUsageKeys } from './usageTracker'; import type { CompletedActions } from './webviews/home/protocol'; @@ -48,6 +49,7 @@ export class Storage implements Disposable { key: T, defaultValue: NonNullable>, ): NonNullable>; + @debug({ logThreshold: 50 }) get( key: T, defaultValue?: GlobalStoragePathValue, @@ -55,24 +57,29 @@ export class Storage implements Disposable { return this.context.globalState.get(`gitlens:${key}`, defaultValue); } + @debug({ logThreshold: 250 }) async delete(key: T): Promise { await this.context.globalState.update(`gitlens:${key}`, undefined); this._onDidChange.fire({ key: key, workspace: false }); } + @debug({ args: { 1: false }, logThreshold: 250 }) async store(key: T, value: GlobalStoragePathValue): Promise { await this.context.globalState.update(`gitlens:${key}`, value); this._onDidChange.fire({ key: key, workspace: false }); } + @debug({ args: false, logThreshold: 250 }) async getSecret(key: SecretKeys): Promise { return this.context.secrets.get(key); } + @debug({ args: false, logThreshold: 250 }) async deleteSecret(key: SecretKeys): Promise { return this.context.secrets.delete(key); } + @debug({ args: false, logThreshold: 250 }) async storeSecret(key: SecretKeys, value: string): Promise { return this.context.secrets.store(key, value); } @@ -82,6 +89,7 @@ export class Storage implements Disposable { key: T, defaultValue: NonNullable>, ): NonNullable>; + @debug({ logThreshold: 25 }) getWorkspace( key: T, defaultValue?: WorkspaceStoragePathValue, @@ -89,11 +97,13 @@ export class Storage implements Disposable { return this.context.workspaceState.get(`gitlens:${key}`, defaultValue); } + @debug({ logThreshold: 250 }) async deleteWorkspace(key: T): Promise { await this.context.workspaceState.update(`gitlens:${key}`, undefined); this._onDidChange.fire({ key: key, workspace: true }); } + @debug({ args: { 1: false }, logThreshold: 250 }) async storeWorkspace(key: T, value: WorkspaceStoragePathValue): Promise { await this.context.workspaceState.update(`gitlens:${key}`, value); this._onDidChange.fire({ key: key, workspace: true }); diff --git a/src/system/decorators/log.ts b/src/system/decorators/log.ts index 79a88f3..d7e747c 100644 --- a/src/system/decorators/log.ts +++ b/src/system/decorators/log.ts @@ -67,6 +67,7 @@ interface LogOptions any> { exit?(result: PromiseType>): string; prefix?(context: LogContext, ...args: Parameters): string; sanitize?(key: string, value: any): any; + logThreshold?: number; scoped?: boolean; singleLine?: boolean; timed?: boolean; @@ -93,6 +94,7 @@ export function log any>(options?: LogOptions, deb let exitFn: LogOptions['exit'] | undefined; let prefixFn: LogOptions['prefix'] | undefined; let sanitizeFn: LogOptions['sanitize'] | undefined; + let logThreshold = 0; let scoped = false; let singleLine = false; let timed = true; @@ -104,12 +106,18 @@ export function log any>(options?: LogOptions, deb exit: exitFn, prefix: prefixFn, sanitize: sanitizeFn, + logThreshold = 0, scoped = true, singleLine = false, timed = true, } = options); } + if (logThreshold > 0) { + singleLine = true; + timed = true; + } + if (timed) { scoped = true; } @@ -264,10 +272,11 @@ export function log any>(options?: LogOptions, deb } const logResult = (r: any) => { + let duration: number | undefined; let exitLogFn; let timing; if (start != null) { - const duration = getDurationMilliseconds(start); + duration = getDurationMilliseconds(start); if (duration > Logger.slowCallWarningThreshold) { exitLogFn = warnFn; timing = ` \u2022 ${duration} ms (slow)`; @@ -292,13 +301,15 @@ export function log any>(options?: LogOptions, deb } if (singleLine) { - exitLogFn( - `${prefix}${enter}${ - loggableParams && (debug || Logger.enabled(LogLevel.Debug) || Logger.isDebugging) - ? `(${loggableParams})` - : emptyStr - } ${exit}${scope?.exitDetails ? scope.exitDetails : emptyStr}${timing}`, - ); + if (logThreshold === 0 || duration! > logThreshold) { + exitLogFn( + `${prefix}${enter}${ + loggableParams && (debug || Logger.enabled(LogLevel.Debug) || Logger.isDebugging) + ? `(${loggableParams})` + : emptyStr + } ${exit}${scope?.exitDetails ? scope.exitDetails : emptyStr}${timing}`, + ); + } } else { exitLogFn( `${prefix}${