From b5f3b0a751aae75cbec0d1196b1ec99688eed999 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 11 Jun 2018 22:31:38 -0400 Subject: [PATCH] Fixes #412 - Respects output level for tracing when debugging --- CHANGELOG.md | 4 ++++ src/logger.ts | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94183ee..aefd96c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] +### Fixed +- Fixes [#400](https://github.com/eamodio/vscode-gitlens/issues/412) - GitLens logging to debug console when debugging different extension + ## [8.3.5] - 2018-06-08 ### Fixed - Fixes more instances of [#295](https://github.com/eamodio/vscode-gitlens/issues/295)and [#318](https://github.com/eamodio/vscode-gitlens/issues/318) - Any error encountered during the search for repositories could cause GitLens to die diff --git a/src/logger.ts b/src/logger.ts index 7f52965..ece1b6e 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -38,21 +38,25 @@ export class Logger { } static log(message?: any, ...params: any[]): void { + if (this.level !== OutputLevel.Verbose && this.level !== OutputLevel.Debug) return; + if (Logger.isDebugging) { console.log(this.timestamp, ConsolePrefix, message, ...params); } - if (this.output !== undefined && (this.level === OutputLevel.Verbose || this.level === OutputLevel.Debug)) { + if (this.output !== undefined) { this.output.appendLine((Logger.isDebugging ? [this.timestamp, message, ...params] : [message, ...params]).join(' ')); } } static error(ex: Error, classOrMethod?: string, ...params: any[]): void { + if (this.level === OutputLevel.Silent) return; + if (Logger.isDebugging) { console.error(this.timestamp, ConsolePrefix, classOrMethod, ...params, ex); } - if (this.output !== undefined && this.level !== OutputLevel.Silent) { + if (this.output !== undefined) { this.output.appendLine((Logger.isDebugging ? [this.timestamp, classOrMethod, ...params, ex] : [classOrMethod, ...params, ex]).join(' ')); } @@ -60,11 +64,13 @@ export class Logger { } static warn(message?: any, ...params: any[]): void { + if (this.level === OutputLevel.Silent) return; + if (Logger.isDebugging) { console.warn(this.timestamp, ConsolePrefix, message, ...params); } - if (this.output !== undefined && this.level !== OutputLevel.Silent) { + if (this.output !== undefined) { this.output.appendLine((Logger.isDebugging ? [this.timestamp, message, ...params] : [message, ...params]).join(' ')); } } @@ -88,11 +94,13 @@ export class Logger { private static _isDebugging: boolean | undefined; static get isDebugging() { if (this._isDebugging === undefined) { - const args = process.execArgv; + try { + const args = process.execArgv; - this._isDebugging = args - ? args.some(arg => isDebuggingRegex.test(arg)) - : false; + this._isDebugging = args + ? args.some(arg => isDebuggingRegex.test(arg)) + : false; + } catch { } } return this._isDebugging;