Browse Source

Fixes logging to clean up on extension deactivate

main
Eric Amodio 7 years ago
parent
commit
780423b195
4 changed files with 42 additions and 32 deletions
  1. +1
    -1
      package.json
  2. +1
    -7
      src/configuration.ts
  3. +2
    -0
      src/extension.ts
  4. +38
    -24
      src/logger.ts

+ 1
- 1
package.json View File

@ -653,8 +653,8 @@
}, },
"devDependencies": { "devDependencies": {
"@types/copy-paste": "^1.1.30", "@types/copy-paste": "^1.1.30",
"@types/node": "^7.0.5",
"@types/mocha": "^2.2.39", "@types/mocha": "^2.2.39",
"@types/node": "^7.0.5",
"@types/tmp": "^0.0.32", "@types/tmp": "^0.0.32",
"mocha": "^3.2.0", "mocha": "^3.2.0",
"tslint": "^4.4.2", "tslint": "^4.4.2",

+ 1
- 7
src/configuration.ts View File

@ -1,5 +1,6 @@
'use strict'; 'use strict';
import { Commands } from './commands'; import { Commands } from './commands';
import { OutputLevel } from './logger';
export type BlameAnnotationStyle = 'compact' | 'expanded' | 'trailing'; export type BlameAnnotationStyle = 'compact' | 'expanded' | 'trailing';
export const BlameAnnotationStyle = { export const BlameAnnotationStyle = {
@ -90,13 +91,6 @@ export interface IStatusBarConfig {
command: StatusBarCommand; command: StatusBarCommand;
} }
export type OutputLevel = 'silent' | 'errors' | 'verbose';
export const OutputLevel = {
Silent: 'silent' as OutputLevel,
Errors: 'errors' as OutputLevel,
Verbose: 'verbose' as OutputLevel
};
export interface IAdvancedConfig { export interface IAdvancedConfig {
caching: { caching: {
enabled: boolean; enabled: boolean;

+ 2
- 0
src/extension.ts View File

@ -27,6 +27,8 @@ import { Logger } from './logger';
// this method is called when your extension is activated // this method is called when your extension is activated
export async function activate(context: ExtensionContext) { export async function activate(context: ExtensionContext) {
Logger.configure(context);
// Workspace not using a folder. No access to git repo. // Workspace not using a folder. No access to git repo.
if (!workspace.rootPath) { if (!workspace.rootPath) {
Logger.warn('GitLens inactive: no rootPath'); Logger.warn('GitLens inactive: no rootPath');

+ 38
- 24
src/logger.ts View File

@ -1,58 +1,72 @@
'use strict'; 'use strict';
import { Objects } from './system';
import { OutputChannel, window, workspace } from 'vscode';
import { IAdvancedConfig, OutputLevel } from './configuration';
import { ExtensionContext, OutputChannel, window, workspace } from 'vscode';
import { IAdvancedConfig } from './configuration';
let config: IAdvancedConfig;
const ConfigurationName = 'gitlens';
const OutputChannelName = 'GitLens';
const ConsolePrefix = `[${OutputChannelName}]`;
export type OutputLevel = 'silent' | 'errors' | 'verbose';
export const OutputLevel = {
Silent: 'silent' as OutputLevel,
Errors: 'errors' as OutputLevel,
Verbose: 'verbose' as OutputLevel
};
let debug = false;
let level: OutputLevel = OutputLevel.Silent;
let output: OutputChannel; let output: OutputChannel;
workspace.onDidChangeConfiguration(onConfigurationChange);
onConfigurationChange();
function onConfigurationChanged() {
const cfg = workspace.getConfiguration(ConfigurationName).get<IAdvancedConfig>('advanced');
function onConfigurationChange() {
const cfg = workspace.getConfiguration('gitlens').get<IAdvancedConfig>('advanced');
if (cfg.debug !== debug || cfg.output.level !== level) {
debug = cfg.debug;
level = cfg.output.level;
if (!Objects.areEquivalent(cfg.output, config && config.output)) {
if (cfg.output.level === OutputLevel.Silent) {
if (level === OutputLevel.Silent) {
output && output.dispose(); output && output.dispose();
} }
else if (!output) {
output = window.createOutputChannel('GitLens');
else {
output = output && window.createOutputChannel(OutputChannelName);
} }
} }
config = cfg;
} }
export class Logger { export class Logger {
static configure(context: ExtensionContext) {
context.subscriptions.push(workspace.onDidChangeConfiguration(onConfigurationChanged));
onConfigurationChanged();
}
static log(message?: any, ...params: any[]): void { static log(message?: any, ...params: any[]): void {
if (config.debug) {
console.log('[GitLens]', message, ...params);
if (debug && level !== OutputLevel.Silent) {
console.log(ConsolePrefix, message, ...params);
} }
if (config.output.level === OutputLevel.Verbose) {
if (level === OutputLevel.Verbose) {
output.appendLine([message, ...params].join(' ')); output.appendLine([message, ...params].join(' '));
} }
} }
static error(message?: any, ...params: any[]): void { static error(message?: any, ...params: any[]): void {
if (config.debug) {
console.error('[GitLens]', message, ...params);
if (debug) {
console.error(ConsolePrefix, message, ...params);
} }
if (config.output.level !== OutputLevel.Silent) {
if (level !== OutputLevel.Silent) {
output.appendLine([message, ...params].join(' ')); output.appendLine([message, ...params].join(' '));
} }
} }
static warn(message?: any, ...params: any[]): void { static warn(message?: any, ...params: any[]): void {
if (config.debug) {
console.warn('[GitLens]', message, ...params);
if (debug) {
console.warn(ConsolePrefix, message, ...params);
} }
if (config.output.level !== OutputLevel.Silent) {
if (level !== OutputLevel.Silent) {
output.appendLine([message, ...params].join(' ')); output.appendLine([message, ...params].join(' '));
} }
} }
}
}

Loading…
Cancel
Save