Przeglądaj źródła

Fixes logging to clean up on extension deactivate

main
Eric Amodio 7 lat temu
rodzic
commit
780423b195
4 zmienionych plików z 42 dodań i 32 usunięć
  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 Wyświetl plik

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

+ 1
- 7
src/configuration.ts Wyświetl plik

@ -1,5 +1,6 @@
'use strict';
import { Commands } from './commands';
import { OutputLevel } from './logger';
export type BlameAnnotationStyle = 'compact' | 'expanded' | 'trailing';
export const BlameAnnotationStyle = {
@ -90,13 +91,6 @@ export interface IStatusBarConfig {
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 {
caching: {
enabled: boolean;

+ 2
- 0
src/extension.ts Wyświetl plik

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

+ 38
- 24
src/logger.ts Wyświetl plik

@ -1,58 +1,72 @@
'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;
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();
}
else if (!output) {
output = window.createOutputChannel('GitLens');
else {
output = output && window.createOutputChannel(OutputChannelName);
}
}
config = cfg;
}
export class Logger {
static configure(context: ExtensionContext) {
context.subscriptions.push(workspace.onDidChangeConfiguration(onConfigurationChanged));
onConfigurationChanged();
}
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(' '));
}
}
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(' '));
}
}
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(' '));
}
}
}
}

Ładowanie…
Anuluj
Zapisz