vscode-texinfo/src/logger.ts

41 lines
917 B
TypeScript
Raw Normal View History

2020-10-22 22:37:47 +00:00
/**
* logger.ts
*
* @author CismonX <admin@cismon.net>
* @license MIT
*/
import * as vscode from 'vscode';
/**
* Logger which prints message to VSCode output channel.
*/
2020-10-24 21:45:32 +00:00
export default class Logger implements vscode.Disposable {
2020-10-22 22:37:47 +00:00
private static singleton?: Logger;
2020-10-24 15:50:20 +00:00
static get instance() {
2020-10-22 22:37:47 +00:00
return Logger.singleton ??= new Logger();
}
2020-10-24 21:45:32 +00:00
static log(message: string) {
const dateTime = new Date().toLocaleString(undefined, { hour12: false });
Logger.instance.outputChannel.appendLine(`[ ${dateTime} ]\n${message}`);
2020-10-22 22:37:47 +00:00
}
2020-10-24 21:45:32 +00:00
static show() {
Logger.instance.outputChannel.show(true);
2020-10-22 22:37:47 +00:00
}
2020-10-24 21:45:32 +00:00
private outputChannel: vscode.OutputChannel;
dispose() {
Logger.instance.outputChannel.dispose();
Logger.singleton = undefined;
2020-10-22 22:37:47 +00:00
}
2020-10-24 21:45:32 +00:00
private constructor() {
this.outputChannel = vscode.window.createOutputChannel('Texinfo');
2020-10-22 22:37:47 +00:00
}
}