Skip to content

Commit a1ad550

Browse files
authored
Adopt cool new log filtering convention (#6645)
1 parent 25e3680 commit a1ad550

File tree

9 files changed

+30
-26
lines changed

9 files changed

+30
-26
lines changed

src/api/api1.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const enum Status {
7474
}
7575

7676
export class GitApiImpl extends Disposable implements API, IGit {
77+
static readonly ID = 'GitAPI';
7778
private static _handlePool: number = 0;
7879
private _providers = new Map<number, IGit>();
7980

@@ -120,13 +121,13 @@ export class GitApiImpl extends Disposable implements API, IGit {
120121
}
121122

122123
registerGitProvider(provider: IGit): vscode.Disposable {
123-
Logger.appendLine(`Registering git provider`);
124+
Logger.appendLine(`Registering git provider`, GitApiImpl.ID);
124125
const handle = this._nextHandle();
125126
this._providers.set(handle, provider);
126127

127128
this._register(provider.onDidCloseRepository(e => this._onDidCloseRepository.fire(e)));
128129
this._register(provider.onDidOpenRepository(e => {
129-
Logger.appendLine(`Repository ${e.rootUri} has been opened`);
130+
Logger.appendLine(`Repository ${e.rootUri} has been opened`, GitApiImpl.ID);
130131
this._updateReposContext();
131132
this._onDidOpenRepository.fire(e);
132133
}));

src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ export function registerCommands(
825825
}
826826

827827
if (!pullRequestModel) {
828-
Logger.appendLine('No pull request found.');
828+
Logger.appendLine('No pull request found.', logId);
829829
return;
830830
}
831831

src/common/logger.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class Log extends Disposable {
1818

1919
public startPerfMarker(marker: string) {
2020
const startTime = performance.now();
21-
this._outputChannel.appendLine(`PERF_MARKER> Start ${marker}`);
21+
this._outputChannel.appendLine(`[PERF_MARKER] Start ${marker}`);
2222
this._activePerfMarkers.set(marker, startTime);
2323
}
2424

2525
public endPerfMarker(marker: string) {
2626
const endTime = performance.now();
27-
this._outputChannel.appendLine(`PERF_MARKER> End ${marker}: ${endTime - this._activePerfMarkers.get(marker)!} ms`);
27+
this._outputChannel.appendLine(`[PERF_MARKER] End ${marker}: ${endTime - this._activePerfMarkers.get(marker)!} ms`);
2828
this._activePerfMarkers.delete(marker);
2929
}
3030

@@ -38,7 +38,7 @@ class Log extends Disposable {
3838
message = JSON.stringify(message);
3939
}
4040
}
41-
return component ? `${component}> ${message}` : message;
41+
return component ? `[${component}] ${message}` : message;
4242
}
4343

4444
public trace(message: any, component: string) {
@@ -49,7 +49,7 @@ class Log extends Disposable {
4949
this._outputChannel.debug(this.logString(message, component));
5050
}
5151

52-
public appendLine(message: any, component?: string) {
52+
public appendLine(message: any, component: string) {
5353
this._outputChannel.info(this.logString(message, component));
5454
}
5555

src/common/temporaryState.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Logger from './logger';
99
let tempState: TemporaryState | undefined;
1010

1111
export class TemporaryState extends vscode.Disposable {
12+
static readonly ID = 'TemporaryState';
1213
private readonly SUBPATH = 'temp';
1314
private readonly disposables: vscode.Disposable[] = [];
1415
private readonly persistInSessionDisposables: vscode.Disposable[] = [];
@@ -86,12 +87,12 @@ export class TemporaryState extends vscode.Disposable {
8687
try {
8788
await vscode.workspace.fs.delete(tempState.path, { recursive: true });
8889
} catch (e) {
89-
Logger.appendLine(`TemporaryState> Error in initialization: ${e.message}`);
90+
Logger.appendLine(`Error in initialization: ${e.message}`, TemporaryState.ID);
9091
}
9192
try {
9293
await vscode.workspace.fs.createDirectory(tempState.path);
9394
} catch (e) {
94-
Logger.appendLine(`TemporaryState> Error in initialization: ${e.message}`);
95+
Logger.appendLine(`Error in initialization: ${e.message}`, TemporaryState.ID);
9596
}
9697
context.subscriptions.push(tempState);
9798
return tempState;

src/extension.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const ingestionKey = '0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-f
4848

4949
let telemetry: ExperimentationTelemetry;
5050

51+
const ACTIVATION = 'Activation';
52+
5153
async function init(
5254
context: vscode.ExtensionContext,
5355
git: GitApiImpl,
@@ -60,7 +62,7 @@ async function init(
6062
createPrHelper: CreatePullRequestHelper
6163
): Promise<void> {
6264
context.subscriptions.push(Logger);
63-
Logger.appendLine('Git repository found, initializing review manager and pr tree view.');
65+
Logger.appendLine('Git repository found, initializing review manager and pr tree view.', ACTIVATION);
6466

6567
context.subscriptions.push(credentialStore.onDidChangeSessions(async e => {
6668
if (e.provider.id === 'github') {
@@ -163,7 +165,7 @@ async function init(
163165
context.subscriptions.push(reviewsManager);
164166

165167
git.onDidChangeState(() => {
166-
Logger.appendLine(`Git initialization state changed: state=${git.state}`);
168+
Logger.appendLine(`Git initialization state changed: state=${git.state}`, ACTIVATION);
167169
reviewsManager.reviewManagers.forEach(reviewManager => reviewManager.updateState(true));
168170
});
169171

@@ -172,7 +174,7 @@ async function init(
172174
// Make sure we don't already have a folder manager for this repo.
173175
const existing = reposManager.folderManagers.find(manager => manager.repository.rootUri.toString() === repo.rootUri.toString());
174176
if (existing) {
175-
Logger.appendLine(`Repo ${repo.rootUri} has already been setup.`);
177+
Logger.appendLine(`Repo ${repo.rootUri} has already been setup.`, ACTIVATION);
176178
return;
177179
}
178180
const newFolderManager = new FolderRepositoryManager(reposManager.folderManagers.length, context, repo, telemetry, git, credentialStore, createPrHelper);
@@ -195,7 +197,7 @@ async function init(
195197
addRepo();
196198
tree.notificationProvider.refreshOrLaunchPolling();
197199
const disposable = repo.state.onDidChange(() => {
198-
Logger.appendLine(`Repo state for ${repo.rootUri} changed.`);
200+
Logger.appendLine(`Repo state for ${repo.rootUri} changed.`, ACTIVATION);
199201
addRepo();
200202
disposable.dispose();
201203
});
@@ -410,9 +412,9 @@ async function deferredActivate(context: vscode.ExtensionContext, apiImpl: GitAp
410412
const prTree = new PullRequestsTreeDataProvider(telemetry, context, reposManager);
411413
context.subscriptions.push(prTree);
412414
context.subscriptions.push(credentialStore.onDidGetSession(() => prTree.refresh(undefined, true)));
413-
Logger.appendLine('Looking for git repository');
415+
Logger.appendLine('Looking for git repository', ACTIVATION);
414416
const repositories = apiImpl.repositories;
415-
Logger.appendLine(`Found ${repositories.length} repositories during activation`);
417+
Logger.appendLine(`Found ${repositories.length} repositories during activation`, ACTIVATION);
416418
const createPrHelper = new CreatePullRequestHelper();
417419
context.subscriptions.push(createPrHelper);
418420

src/github/folderRepositoryManager.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@ export class FolderRepositoryManager extends Disposable {
419419

420420
if (activeRemotes.length) {
421421
await vscode.commands.executeCommand('setContext', 'github:hasGitHubRemotes', true);
422-
Logger.appendLine(`Found GitHub remote for folder ${this.repository.rootUri.fsPath}`);
422+
Logger.appendLine(`Found GitHub remote for folder ${this.repository.rootUri.fsPath}`, this.id);
423423
} else {
424-
Logger.appendLine(`No GitHub remotes found for folder ${this.repository.rootUri.fsPath}`);
424+
Logger.appendLine(`No GitHub remotes found for folder ${this.repository.rootUri.fsPath}`, this.id);
425425
}
426426

427427
return activeRemotes;
@@ -463,7 +463,7 @@ export class FolderRepositoryManager extends Disposable {
463463

464464
private async doUpdateRepositories(silent: boolean): Promise<boolean> {
465465
if (this._git.state === 'uninitialized') {
466-
Logger.appendLine('Cannot updates repositories as git is uninitialized');
466+
Logger.appendLine('Cannot updates repositories as git is uninitialized', this.id);
467467

468468
return false;
469469
}
@@ -601,7 +601,7 @@ export class FolderRepositoryManager extends Disposable {
601601
}
602602
}
603603
} catch (e) {
604-
Logger.appendLine(`Missing upstream check failed: ${e}`);
604+
Logger.appendLine(`Missing upstream check failed: ${e}`, this.id);
605605
// ignore
606606
}
607607
return false;
@@ -697,7 +697,7 @@ export class FolderRepositoryManager extends Disposable {
697697
}
698698

699699
if (this._mentionableUsers) {
700-
Logger.appendLine('Using in-memory cached mentionable users.');
700+
Logger.appendLine('Using in-memory cached mentionable users.', this.id);
701701
return this._mentionableUsers;
702702
}
703703

@@ -717,7 +717,7 @@ export class FolderRepositoryManager extends Disposable {
717717
}
718718

719719
if (this._assignableUsers) {
720-
Logger.appendLine('Using in-memory cached assignable users.');
720+
Logger.appendLine('Using in-memory cached assignable users.', this.id);
721721
return this._assignableUsers;
722722
}
723723

@@ -754,7 +754,7 @@ export class FolderRepositoryManager extends Disposable {
754754
}
755755

756756
if (this._teamReviewers) {
757-
Logger.appendLine('Using in-memory cached team reviewers.');
757+
Logger.appendLine('Using in-memory cached team reviewers.', this.id);
758758
return this._teamReviewers;
759759
}
760760

src/github/notifications.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ export class NotificationProvider extends Disposable {
283283
if (pollTimeSuggested !== this._pollingDuration) {
284284
this._pollingDuration = pollTimeSuggested;
285285
if (this._pollingHandler && NotificationProvider.isPRNotificationsOn()) {
286-
Logger.appendLine('Notifications: Clearing interval');
286+
Logger.appendLine('Notifications: Clearing interval', NotificationProvider.ID);
287287
clearInterval(this._pollingHandler);
288-
Logger.appendLine(`Notifications: Starting new polling interval with ${this._pollingDuration}`);
288+
Logger.appendLine(`Notifications: Starting new polling interval with ${this._pollingDuration}`, NotificationProvider.ID);
289289
this.startPolling();
290290
}
291291
}

src/github/repositoriesManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class RepositoriesManager extends Disposable {
196196
if (enterprise) {
197197
const remoteToUse = getEnterpriseUri()?.toString() ?? (enterpriseRemotes.length ? enterpriseRemotes[0].normalizedHost : (unknownRemotes.length ? unknownRemotes[0].normalizedHost : undefined));
198198
if (enterpriseRemotes.length === 0 && unknownRemotes.length === 0) {
199-
Logger.appendLine(`Enterprise login selected, but no possible enterprise remotes discovered (${dotComRemotes.length} .com)`);
199+
Logger.appendLine(`Enterprise login selected, but no possible enterprise remotes discovered (${dotComRemotes.length} .com)`, RepositoriesManager.ID);
200200
}
201201
if (remoteToUse) {
202202
const promptResult = await vscode.window.showInformationMessage(vscode.l10n.t('Would you like to set up GitHub Pull Requests and Issues to authenticate with the enterprise server {0}?', remoteToUse),

src/view/reviewManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export class ReviewManager extends Disposable {
368368
const { url, branchName, remoteName } = await this.getUpstreamUrlAndName(this._repository.state.HEAD!);
369369
const metadataFromGithub = await this._folderRepoManager.getMatchingPullRequestMetadataFromGitHub(branch, remoteName, url, branchName);
370370
if (metadataFromGithub) {
371-
Logger.appendLine(`Found matching pull request metadata on GitHub for current branch ${branch.name}. Repo: ${metadataFromGithub.owner}/${metadataFromGithub.repositoryName} PR: ${metadataFromGithub.prNumber}`);
371+
Logger.appendLine(`Found matching pull request metadata on GitHub for current branch ${branch.name}. Repo: ${metadataFromGithub.owner}/${metadataFromGithub.repositoryName} PR: ${metadataFromGithub.prNumber}`, this.id);
372372
await PullRequestGitHelper.associateBranchWithPullRequest(
373373
this._repository,
374374
metadataFromGithub.model,

0 commit comments

Comments
 (0)