From f67bf87c539c0287b6c31a7da20177a7a43e93a3 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 9 Feb 2019 12:47:49 -0500 Subject: [PATCH] Renames LogLevel to TraceLevel for consistency with others --- src/logger.ts | 54 ++++++++++++++++++++++---------------------- src/system/decorators/log.ts | 6 ++--- src/ui/config.ts | 4 ++-- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index 5f04bed..2ac8e33 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,11 +1,11 @@ 'use strict'; import { ConfigurationChangeEvent, ExtensionContext, OutputChannel, Uri, window } from 'vscode'; -import { configuration, LogLevel } from './configuration'; +import { configuration, TraceLevel } from './configuration'; import { extensionOutputChannelName } from './constants'; import { getCorrelationContext } from './system'; // import { Telemetry } from './telemetry'; -export { LogLevel } from './configuration'; +export { TraceLevel } from './configuration'; const ConsolePrefix = `[${extensionOutputChannelName}]`; @@ -18,7 +18,7 @@ export interface LogCorrelationContext { } export class Logger { - static level: LogLevel = LogLevel.Silent; + static level: TraceLevel = TraceLevel.Silent; static output: OutputChannel | undefined; static customLoggableFn: ((o: object) => string | undefined) | undefined; @@ -32,9 +32,9 @@ export class Logger { private static onConfigurationChanged(e: ConfigurationChangeEvent) { const section = configuration.name('outputLevel').value; if (configuration.changed(e, section)) { - this.level = configuration.get(section); + this.level = configuration.get(section); - if (this.level === LogLevel.Silent) { + if (this.level === TraceLevel.Silent) { if (this.output !== undefined) { this.output.dispose(); this.output = undefined; @@ -49,7 +49,7 @@ export class Logger { static debug(message: string, ...params: any[]): void; static debug(context: LogCorrelationContext | undefined, message: string, ...params: any[]): void; static debug(contextOrMessage: LogCorrelationContext | string | undefined, ...params: any[]): void { - if (this.level !== LogLevel.Debug && !Logger.isDebugging) return; + if (this.level !== TraceLevel.Debug && !Logger.isDebugging) return; let message; if (typeof contextOrMessage === 'string') { @@ -67,7 +67,7 @@ export class Logger { console.log(this.timestamp, ConsolePrefix, message || '', ...params); } - if (this.output !== undefined && this.level === LogLevel.Debug) { + if (this.output !== undefined && this.level === TraceLevel.Debug) { this.output.appendLine(`${this.timestamp} ${message || ''}${this.toLoggableParams(true, params)}`); } } @@ -75,7 +75,7 @@ export class Logger { static error(ex: Error, message?: string, ...params: any[]): void; static error(ex: Error, context?: LogCorrelationContext, message?: string, ...params: any[]): void; static error(ex: Error, contextOrMessage: LogCorrelationContext | string | undefined, ...params: any[]): void { - if (this.level === LogLevel.Silent && !Logger.isDebugging) return; + if (this.level === TraceLevel.Silent && !Logger.isDebugging) return; let message; if (contextOrMessage === undefined || typeof contextOrMessage === 'string') { @@ -103,7 +103,7 @@ export class Logger { console.error(this.timestamp, ConsolePrefix, message || '', ...params, ex); } - if (this.output !== undefined && this.level !== LogLevel.Silent) { + if (this.output !== undefined && this.level !== TraceLevel.Silent) { this.output.appendLine(`${this.timestamp} ${message || ''}${this.toLoggableParams(false, params)}\n${ex}`); } @@ -117,7 +117,7 @@ export class Logger { static log(message: string, ...params: any[]): void; static log(context: LogCorrelationContext | undefined, message: string, ...params: any[]): void; static log(contextOrMessage: LogCorrelationContext | string | undefined, ...params: any[]): void { - if (this.level !== LogLevel.Verbose && this.level !== LogLevel.Debug && !Logger.isDebugging) { + if (this.level !== TraceLevel.Verbose && this.level !== TraceLevel.Debug && !Logger.isDebugging) { return; } @@ -137,7 +137,7 @@ export class Logger { console.log(this.timestamp, ConsolePrefix, message || '', ...params); } - if (this.output !== undefined && (this.level === LogLevel.Verbose || this.level === LogLevel.Debug)) { + if (this.output !== undefined && (this.level === TraceLevel.Verbose || this.level === TraceLevel.Debug)) { this.output.appendLine(`${this.timestamp} ${message || ''}${this.toLoggableParams(false, params)}`); } } @@ -145,7 +145,7 @@ export class Logger { static logWithDebugParams(message: string, ...params: any[]): void; static logWithDebugParams(context: LogCorrelationContext | undefined, message: string, ...params: any[]): void; static logWithDebugParams(contextOrMessage: LogCorrelationContext | string | undefined, ...params: any[]): void { - if (this.level !== LogLevel.Verbose && this.level !== LogLevel.Debug && !Logger.isDebugging) { + if (this.level !== TraceLevel.Verbose && this.level !== TraceLevel.Debug && !Logger.isDebugging) { return; } @@ -165,7 +165,7 @@ export class Logger { console.log(this.timestamp, ConsolePrefix, message || '', ...params); } - if (this.output !== undefined && (this.level === LogLevel.Verbose || this.level === LogLevel.Debug)) { + if (this.output !== undefined && (this.level === TraceLevel.Verbose || this.level === TraceLevel.Debug)) { this.output.appendLine(`${this.timestamp} ${message || ''}${this.toLoggableParams(true, params)}`); } } @@ -173,7 +173,7 @@ export class Logger { static warn(message: string, ...params: any[]): void; static warn(context: LogCorrelationContext | undefined, message: string, ...params: any[]): void; static warn(contextOrMessage: LogCorrelationContext | string | undefined, ...params: any[]): void { - if (this.level === LogLevel.Silent && !Logger.isDebugging) return; + if (this.level === TraceLevel.Silent && !Logger.isDebugging) return; let message; if (typeof contextOrMessage === 'string') { @@ -191,7 +191,7 @@ export class Logger { console.warn(this.timestamp, ConsolePrefix, message || '', ...params); } - if (this.output !== undefined && this.level !== LogLevel.Silent) { + if (this.output !== undefined && this.level !== TraceLevel.Silent) { this.output.appendLine(`${this.timestamp} ${message || ''}${this.toLoggableParams(false, params)}`); } } @@ -244,19 +244,8 @@ export class Logger { .replace(/\..+/, '')}:${('00' + now.getUTCMilliseconds()).slice(-3)}]`; } - static gitOutput: OutputChannel | undefined; - - static logGitCommand(command: string, ex?: Error): void { - if (this.level !== LogLevel.Debug) return; - - if (this.gitOutput === undefined) { - this.gitOutput = window.createOutputChannel(`${extensionOutputChannelName} (Git)`); - } - this.gitOutput.appendLine(`${this.timestamp} ${command}${ex != null ? `\n\n${ex.toString()}` : ''}`); - } - private static toLoggableParams(debugOnly: boolean, params: any[]) { - if (params.length === 0 || (debugOnly && this.level !== LogLevel.Debug && !Logger.isDebugging)) { + if (params.length === 0 || (debugOnly && this.level !== TraceLevel.Debug && !Logger.isDebugging)) { return ''; } @@ -274,4 +263,15 @@ export class Logger { return this._isDebugging; } + + static gitOutput: OutputChannel | undefined; + + static logGitCommand(command: string, ex?: Error): void { + if (this.level !== TraceLevel.Debug) return; + + if (this.gitOutput === undefined) { + this.gitOutput = window.createOutputChannel(`${extensionOutputChannelName} (Git)`); + } + this.gitOutput.appendLine(`${this.timestamp} ${command}${ex != null ? `\n\n${ex.toString()}` : ''}`); + } } diff --git a/src/system/decorators/log.ts b/src/system/decorators/log.ts index bcea0d6..40bf784 100644 --- a/src/system/decorators/log.ts +++ b/src/system/decorators/log.ts @@ -1,5 +1,5 @@ 'use strict'; -import { LogCorrelationContext, Logger, LogLevel } from '../../logger'; +import { LogCorrelationContext, Logger, TraceLevel } from '../../logger'; import { Functions } from './../function'; import { Strings } from './../string'; @@ -98,8 +98,8 @@ export function log( if ( (!Logger.isDebugging && - Logger.level !== LogLevel.Debug && - !(Logger.level === LogLevel.Verbose && !options.debug)) || + Logger.level !== TraceLevel.Debug && + !(Logger.level === TraceLevel.Verbose && !options.debug)) || (typeof options.condition === 'function' && !options.condition(...args)) ) { return fn!.apply(this, args); diff --git a/src/ui/config.ts b/src/ui/config.ts index 5ff3b17..42e94f1 100644 --- a/src/ui/config.ts +++ b/src/ui/config.ts @@ -67,7 +67,7 @@ export interface Config { }; }; modes: { [key: string]: ModeConfig }; - outputLevel: LogLevel; + outputLevel: TraceLevel; recentChanges: { highlight: { locations: HighlightLocations[]; @@ -157,7 +157,7 @@ export enum KeyMap { None = 'none' } -export enum LogLevel { +export enum TraceLevel { Silent = 'silent', Errors = 'errors', Verbose = 'verbose',