Skip to content

Commit

Permalink
Adds mode logging - #725
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed May 1, 2019
1 parent 751ad0e commit 8ec5ceb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/commands/switchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ import { configuration } from '../configuration';
import { Container } from '../container';
import { ModesQuickPick } from '../quickpicks';
import { command, Command, Commands } from './common';
import { log } from '../system/decorators/log';
import { Logger } from '../logger';

@command()
export class SwitchModeCommand extends Command {
constructor() {
super(Commands.SwitchMode);
}

@log({ args: false, correlate: true, singleLine: true, timed: false })
async execute() {
const cc = Logger.getCorrelationContext();

const pick = await ModesQuickPick.show();
if (pick === undefined) return;

if (cc) {
cc.exitDetails = ` \u2014 mode=${pick.key || ''}`;
}

const active = Container.config.mode.active;
if (active === pick.key) return;

Expand All @@ -39,6 +48,7 @@ export class ToggleReviewModeCommand extends Command {
super(Commands.ToggleReviewMode);
}

@log({ args: false, singleLine: true, timed: false })
async execute() {
if (!Object.keys(Container.config.modes).includes('review')) return;

Expand All @@ -53,6 +63,7 @@ export class ToggleZenModeCommand extends Command {
super(Commands.ToggleZenMode);
}

@log({ args: false, singleLine: true, timed: false })
async execute() {
if (!Object.keys(Container.config.modes).includes('zen')) return;

Expand Down
10 changes: 7 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function activate(context: ExtensionContext) {

const enabled = workspace.getConfiguration('git', null!).get<boolean>('enabled', true);
if (!enabled) {
Logger.log(`GitLens(v${gitlensVersion}) was NOT activated -- "git.enabled": false`);
Logger.log(`GitLens (v${gitlensVersion}) was NOT activated -- "git.enabled": false`);
setCommandContext(CommandContext.Enabled, false);

void Messages.showGitDisabledErrorMessage();
Expand All @@ -55,7 +55,7 @@ export async function activate(context: ExtensionContext) {
await GitService.initialize();
}
catch (ex) {
Logger.error(ex, `GitLens(v${gitlensVersion}).activate`);
Logger.error(ex, `GitLens (v${gitlensVersion}) activate`);
setCommandContext(CommandContext.Enabled, false);

if (ex.message.includes('Unable to find git')) {
Expand Down Expand Up @@ -88,7 +88,11 @@ export async function activate(context: ExtensionContext) {
// Constantly over my data cap so stop collecting initialized event
// Telemetry.trackEvent('initialized', Objects.flatten(cfg, 'config', true));

Logger.log(`GitLens(v${gitlensVersion}) activated ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`);
Logger.log(
`GitLens (v${gitlensVersion}${cfg.mode.active ? `, mode: ${cfg.mode.active}` : ''}) activated ${
GlyphChars.Dot
} ${Strings.getDurationMilliseconds(start)} ms`
);
}

export function deactivate() {
Expand Down
2 changes: 1 addition & 1 deletion src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class Logger {
}

const loggableParams = params.map(p => this.toLoggable(p)).join(', ');
return ` \u2014 ${loggableParams}` || emptyStr;
return loggableParams.length !== 0 ? ` \u2014 ${loggableParams}` : emptyStr;
}

private static _isDebugging: boolean | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/system/decorators/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export function log<T extends (...arg: any) => any>(
}
}

if (options.timed || options.exit != null) {
if (options.singleLine || options.timed || options.exit != null) {
const start = options.timed ? process.hrtime() : undefined;

const logError = (ex: Error) => {
Expand Down

0 comments on commit 8ec5ceb

Please sign in to comment.