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

Use lazy for creating output channel

上级 ed3e6451
......@@ -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<string>('markdown.trace', 'off'));
return Trace.fromString(vscode.workspace.getConfiguration().get<string>('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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册