Skip to content

Commit

Permalink
Adds enable/disable debug logging commands
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Apr 7, 2021
1 parent 9708ae1 commit 9594bfc
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Adds Gitea remote provider support — closes [#1379](https://github.com/eamodio/vscode-gitlens/issues/1379) thanks to [PR #1396](https://github.com/eamodio/vscode-gitlens/pull/1396) by Nils K ([septatrix](https://github.com/septatrix))
- Adds a `gitlens.advanced.commitOrdering` setting to specify the order by which commits will be shown. If unspecified, commits will be shown in reverse chronological order — closes [#1257](https://github.com/eamodio/vscode-gitlens/issues/1257) thanks to [PR #1344](https://github.com/eamodio/vscode-gitlens/pull/1344) by Andy Tang ([thewindsofwinter](https://github.com/thewindsofwinter)) and Shashank Shastri ([Shashank-Shastri](https://github.com/Shashank-Shastri))
- Adds [documentation](https://github.com/eamodio/vscode-gitlens#side-bar-views-) for the _GitLens: Set Views Layout_ command — thanks to [PR #1404](https://github.com/eamodio/vscode-gitlens/pull/1404) by Asif Kamran Malick ([@akmalick](https://github.com/akmalick))
- Adds an _Enable Debug Logging_ command (`gitlens.enableDebugLogging`) to enable debug logging to the GitLens output channel
- Adds a _Disable Debug Logging_ command (`gitlens.disableDebugLogging`) to disable debug logging to the GitLens output channel

### Fixed

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ Additionally, these integrations provide commands to copy the url of or open, fi
- Adds a _Open Changed Files_ command (`gitlens.openChangedFiles`) to open any files with working tree changes
- Adds a _Close Unchanged Files_ command (`gitlens.closeUnchangedFiles`) to close any files without working tree changes

- Adds an _Enable Debug Logging_ command (`gitlens.enableDebugLogging`) to enable debug logging to the GitLens output channel
- Adds a _Disable Debug Logging_ command (`gitlens.disableDebugLogging`) to disable debug logging to the GitLens output channel

## Menus & Toolbars [#](#menus- 'Menus & Toolbars')

<p align="center">
Expand Down
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2590,6 +2590,7 @@
"suppressCommitHasNoPreviousCommitWarning": false,
"suppressCommitNotFoundWarning": false,
"suppressCreatePullRequestPrompt": false,
"suppressDebugLoggingWarning": false,
"suppressFileNotUnderSourceControlWarning": false,
"suppressGitDisabledWarning": false,
"suppressGitMissingWarning": false,
Expand All @@ -2612,6 +2613,10 @@
"type": "boolean",
"default": false
},
"suppressDebugLoggingWarning": {
"type": "boolean",
"default": false
},
"suppressFileNotUnderSourceControlWarning": {
"type": "boolean",
"default": false
Expand Down Expand Up @@ -5113,6 +5118,16 @@
"command": "gitlens.views.tags.setShowAvatarsOff",
"title": "Hide Avatars",
"category": "GitLens"
},
{
"command": "gitlens.enableDebugLogging",
"title": "Enable Debug Logging",
"category": "GitLens"
},
{
"command": "gitlens.disableDebugLogging",
"title": "Disable Debug Logging",
"category": "GitLens"
}
],
"menus": {
Expand Down Expand Up @@ -6480,6 +6495,14 @@
{
"command": "gitlens.views.tags.setShowAvatarsOff",
"when": "false"
},
{
"command": "gitlens.enableDebugLogging",
"when": "config.gitlens.outputLevel != debug"
},
{
"command": "gitlens.disableDebugLogging",
"when": "config.gitlens.outputLevel != errors"
}
],
"editor/context": [
Expand Down
1 change: 1 addition & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export * from './commands/diffWithWorking';
export * from './commands/externalDiff';
export * from './commands/gitCommands';
export * from './commands/inviteToLiveShare';
export * from './commands/logging';
export * from './commands/openAssociatedPullRequestOnRemote';
export * from './commands/openBranchesOnRemote';
export * from './commands/openBranchOnRemote';
Expand Down
2 changes: 2 additions & 0 deletions src/commands/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export enum Commands {
DiffWithWorkingInDiffRight = 'gitlens.diffWithWorkingInDiffRight',
DiffLineWithWorking = 'gitlens.diffLineWithWorking',
DisconnectRemoteProvider = 'gitlens.disconnectRemoteProvider',
DisableDebugLogging = 'gitlens.disableDebugLogging',
EnableDebugLogging = 'gitlens.enableDebugLogging',
DisableRebaseEditor = 'gitlens.disableRebaseEditor',
EnableRebaseEditor = 'gitlens.enableRebaseEditor',
ExternalDiff = 'gitlens.externalDiff',
Expand Down
25 changes: 25 additions & 0 deletions src/commands/logging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
import { command, Command, Commands } from './common';
import { configuration, TraceLevel } from '../configuration';

@command()
export class EnableDebugLoggingCommand extends Command {
constructor() {
super(Commands.EnableDebugLogging);
}

async execute() {
await configuration.updateEffective('outputLevel', TraceLevel.Debug);
}
}

@command()
export class DisableDebugLoggingCommand extends Command {
constructor() {
super(Commands.DisableDebugLogging);
}

async execute() {
await configuration.updateEffective('outputLevel', TraceLevel.Errors);
}
}
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export interface AdvancedConfig {
suppressCommitHasNoPreviousCommitWarning: boolean;
suppressCommitNotFoundWarning: boolean;
suppressCreatePullRequestPrompt: boolean;
suppressDebugLoggingWarning: boolean;
suppressFileNotUnderSourceControlWarning: boolean;
suppressGitDisabledWarning: boolean;
suppressGitMissingWarning: boolean;
Expand Down
12 changes: 11 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CreatePullRequestActionContext, GitLensApi, OpenPullRequestActionContex
import { Api } from './api/api';
import { Commands, executeCommand, OpenPullRequestOnRemoteCommandArgs, registerCommands } from './commands';
import { CreatePullRequestOnRemoteCommandArgs } from './commands/createPullRequestOnRemote';
import { configuration, Configuration } from './configuration';
import { configuration, Configuration, TraceLevel } from './configuration';
import { ContextKeys, GlobalState, GlyphChars, setContext, SyncedState } from './constants';
import { Container } from './container';
import { Git, GitBranch, GitCommit } from './git/git';
Expand Down Expand Up @@ -158,6 +158,16 @@ export async function activate(context: ExtensionContext): Promise<GitLensApi |
void context.globalState.update(SyncedState.Version, gitlensVersion);
}

if (cfg.outputLevel === TraceLevel.Debug) {
setTimeout(async () => {
if (cfg.outputLevel !== TraceLevel.Debug) return;

if (await Messages.showDebugLoggingWarningMessage()) {
void commands.executeCommand(Commands.DisableDebugLogging);
}
}, 60000);
}

Logger.log(
`GitLens (v${gitlensVersion}${cfg.mode.active ? `, mode: ${cfg.mode.active}` : ''}) activated ${
GlyphChars.Dot
Expand Down
14 changes: 14 additions & 0 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum SuppressedMessages {
CommitHasNoPreviousCommitWarning = 'suppressCommitHasNoPreviousCommitWarning',
CommitNotFoundWarning = 'suppressCommitNotFoundWarning',
CreatePullRequestPrompt = 'suppressCreatePullRequestPrompt',
SuppressDebugLoggingWarning = 'suppressDebugLoggingWarning',
FileNotUnderSourceControlWarning = 'suppressFileNotUnderSourceControlWarning',
GitDisabledWarning = 'suppressGitDisabledWarning',
GitMissingWarning = 'suppressGitMissingWarning',
Expand Down Expand Up @@ -54,6 +55,19 @@ export class Messages {
return result === create;
}

static async showDebugLoggingWarningMessage(): Promise<boolean> {
const disable = { title: 'Disable Debug Logging' };
const result = await Messages.showMessage(
'warn',
'GitLens debug logging is currently enabled. Unless you are reporting an issue, it is recommended to be disabled. Would you like to disable it?',
SuppressedMessages.SuppressDebugLoggingWarning,
{ title: "Don't Show Again" },
disable,
);

return result === disable;
}

static async showGenericErrorMessage(message: string): Promise<MessageItem | undefined> {
const actions: MessageItem[] = [{ title: 'Open Output Channel' }];
const result = await Messages.showMessage(
Expand Down

0 comments on commit 9594bfc

Please sign in to comment.