From 31a8fe2690d7886af57c9a1e80de7b45e6e2dc07 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 7 Jun 2018 16:55:12 -0700 Subject: [PATCH] Use lazy for creating output channel --- .../markdown-language-features/src/logger.ts | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/extensions/markdown-language-features/src/logger.ts b/extensions/markdown-language-features/src/logger.ts index f5a4a776533..4ee89cbb811 100644 --- a/extensions/markdown-language-features/src/logger.ts +++ b/extensions/markdown-language-features/src/logger.ts @@ -3,7 +3,8 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { OutputChannel, window, workspace } from 'vscode'; +import * as vscode from 'vscode'; +import { lazy } from './util/lazy'; enum Trace { Off, @@ -31,7 +32,8 @@ function isString(value: any): value is string { export class Logger { private trace?: Trace; - private _output?: OutputChannel; + + private readonly outputChannel = lazy(() => vscode.window.createOutputChannel('Markdown')); constructor() { this.updateConfiguration(); @@ -39,9 +41,9 @@ export class Logger { public log(message: string, data?: any): void { if (this.trace === Trace.Verbose) { - this.output.appendLine(`[Log - ${(new Date().toLocaleTimeString())}] ${message}`); + this.appendLine(`[Log - ${(new Date().toLocaleTimeString())}] ${message}`); if (data) { - this.output.appendLine(Logger.data2String(data)); + this.appendLine(Logger.data2String(data)); } } } @@ -50,15 +52,12 @@ export class Logger { this.trace = this.readTrace(); } - private get output(): OutputChannel { - if (!this._output) { - this._output = window.createOutputChannel('Markdown'); - } - return this._output; + private appendLine(value: string) { + return this.outputChannel.value.appendLine(value); } private readTrace(): Trace { - return Trace.fromString(workspace.getConfiguration().get('markdown.trace', 'off')); + return Trace.fromString(vscode.workspace.getConfiguration().get('markdown.trace', 'off')); } private static data2String(data: any): string { @@ -73,4 +72,4 @@ export class Logger { } return JSON.stringify(data, undefined, 2); } -} \ No newline at end of file +} -- GitLab