From 8ec5ceb815382f5d8cf0fbed9251f5a175e4d46d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 30 Apr 2019 23:23:00 -0400 Subject: [PATCH] Adds mode logging - #725 --- src/commands/switchMode.ts | 11 +++++++++++ src/extension.ts | 10 +++++++--- src/logger.ts | 2 +- src/system/decorators/log.ts | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/commands/switchMode.ts b/src/commands/switchMode.ts index b6e03be..9c4ca21 100644 --- a/src/commands/switchMode.ts +++ b/src/commands/switchMode.ts @@ -4,6 +4,8 @@ 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 { @@ -11,10 +13,17 @@ export class SwitchModeCommand extends Command { 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; @@ -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; @@ -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; diff --git a/src/extension.ts b/src/extension.ts index 5fe8951..30861e1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -36,7 +36,7 @@ export async function activate(context: ExtensionContext) { const enabled = workspace.getConfiguration('git', null!).get('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(); @@ -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')) { @@ -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() { diff --git a/src/logger.ts b/src/logger.ts index 38422a7..13e3a20 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -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; diff --git a/src/system/decorators/log.ts b/src/system/decorators/log.ts index 85343f3..fedf0df 100644 --- a/src/system/decorators/log.ts +++ b/src/system/decorators/log.ts @@ -190,7 +190,7 @@ export function log 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) => {