提交 31a8fe26 编写于 作者: M Matt Bierner

Use lazy for creating output channel

上级 ed3e6451
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * 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 { enum Trace {
Off, Off,
...@@ -31,7 +32,8 @@ function isString(value: any): value is string { ...@@ -31,7 +32,8 @@ function isString(value: any): value is string {
export class Logger { export class Logger {
private trace?: Trace; private trace?: Trace;
private _output?: OutputChannel;
private readonly outputChannel = lazy(() => vscode.window.createOutputChannel('Markdown'));
constructor() { constructor() {
this.updateConfiguration(); this.updateConfiguration();
...@@ -39,9 +41,9 @@ export class Logger { ...@@ -39,9 +41,9 @@ export class Logger {
public log(message: string, data?: any): void { public log(message: string, data?: any): void {
if (this.trace === Trace.Verbose) { if (this.trace === Trace.Verbose) {
this.output.appendLine(`[Log - ${(new Date().toLocaleTimeString())}] ${message}`); this.appendLine(`[Log - ${(new Date().toLocaleTimeString())}] ${message}`);
if (data) { if (data) {
this.output.appendLine(Logger.data2String(data)); this.appendLine(Logger.data2String(data));
} }
} }
} }
...@@ -50,15 +52,12 @@ export class Logger { ...@@ -50,15 +52,12 @@ export class Logger {
this.trace = this.readTrace(); this.trace = this.readTrace();
} }
private get output(): OutputChannel { private appendLine(value: string) {
if (!this._output) { return this.outputChannel.value.appendLine(value);
this._output = window.createOutputChannel('Markdown');
}
return this._output;
} }
private readTrace(): Trace { private readTrace(): Trace {
return Trace.fromString(workspace.getConfiguration().get<string>('markdown.trace', 'off')); return Trace.fromString(vscode.workspace.getConfiguration().get<string>('markdown.trace', 'off'));
} }
private static data2String(data: any): string { private static data2String(data: any): string {
...@@ -73,4 +72,4 @@ export class Logger { ...@@ -73,4 +72,4 @@ export class Logger {
} }
return JSON.stringify(data, undefined, 2); return JSON.stringify(data, undefined, 2);
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册