mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
Use lazy for creating output channel
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user