From 1088e3e685d70d885c7f3818c810804e6e185714 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 27 Oct 2018 17:07:09 -0400 Subject: [PATCH] Fixes logging --- src/logger.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index 15a8ba0..bc99b15 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -37,26 +37,26 @@ export class Logger { } static debug(message?: any, ...params: any[]): void { - if (this.level !== LogLevel.Debug && !Logger.isDebugging) return; - if (Logger.isDebugging) { - console.log(this.timestamp, ConsolePrefix, message, ...params); + console.log(this.timestamp, ConsolePrefix, message || '', ...params); } + if (this.level !== LogLevel.Debug) return; + if (this.output !== undefined) { - this.output.appendLine(`${this.timestamp} ${message} ${this.toLoggableParams(true, params)}`); + this.output.appendLine(`${this.timestamp} ${message || ''} ${this.toLoggableParams(true, params)}`); } } static error(ex: Error, message?: string, ...params: any[]): void { if (Logger.isDebugging) { - console.error(this.timestamp, ConsolePrefix, message, ...params, ex); + console.error(this.timestamp, ConsolePrefix, message || '', ...params, ex); } if (this.level === LogLevel.Silent) return; if (this.output !== undefined) { - this.output.appendLine(`${this.timestamp} ${message} ${this.toLoggableParams(false, params)}\n${ex}`); + this.output.appendLine(`${this.timestamp} ${message || ''} ${this.toLoggableParams(false, params)}\n${ex}`); } // Telemetry.trackException(ex); @@ -64,37 +64,37 @@ export class Logger { static log(message?: any, ...params: any[]): void { if (Logger.isDebugging) { - console.log(this.timestamp, ConsolePrefix, message, ...params); + console.log(this.timestamp, ConsolePrefix, message || '', ...params); } if (this.level !== LogLevel.Verbose && this.level !== LogLevel.Debug) return; if (this.output !== undefined) { - this.output.appendLine(`${this.timestamp} ${message} ${this.toLoggableParams(false, params)}`); + this.output.appendLine(`${this.timestamp} ${message || ''} ${this.toLoggableParams(false, params)}`); } } static logWithDebugParams(message?: any, ...params: any[]): void { if (Logger.isDebugging) { - console.log(this.timestamp, ConsolePrefix, message, ...params); + console.log(this.timestamp, ConsolePrefix, message || '', ...params); } if (this.level !== LogLevel.Verbose && this.level !== LogLevel.Debug) return; if (this.output !== undefined) { - this.output.appendLine(`${this.timestamp} ${message} ${this.toLoggableParams(true, params)}`); + this.output.appendLine(`${this.timestamp} ${message || ''} ${this.toLoggableParams(true, params)}`); } } static warn(message?: any, ...params: any[]): void { if (Logger.isDebugging) { - console.warn(this.timestamp, ConsolePrefix, message, ...params); + console.warn(this.timestamp, ConsolePrefix, message || '', ...params); } if (this.level === LogLevel.Silent) return; if (this.output !== undefined) { - this.output.appendLine(`${this.timestamp} ${message} ${this.toLoggableParams(false, params)}`); + this.output.appendLine(`${this.timestamp} ${message || ''} ${this.toLoggableParams(false, params)}`); } }