Fix up logs view
This commit is contained in:
parent
d77162ddf1
commit
818812aa2d
2 changed files with 56 additions and 4 deletions
|
|
@ -8,22 +8,25 @@ export enum LogLevel {
|
||||||
}
|
}
|
||||||
|
|
||||||
class LogLine {
|
class LogLine {
|
||||||
|
public timestamp = new Date();
|
||||||
public constructor(public level: LogLevel, public message: string) {}
|
public constructor(public level: LogLevel, public message: string) {}
|
||||||
|
|
||||||
public toString(): string {
|
public toString(): string {
|
||||||
return `${this.formatLevel()}: ${this.message}`;
|
return `| ${this.formatLevel()} | ${this.timestamp.getHours()}:${this.timestamp.getMinutes()}:${this.timestamp.getSeconds()} | ${
|
||||||
|
this.message
|
||||||
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private formatLevel(): string {
|
private formatLevel(): string {
|
||||||
switch (this.level) {
|
switch (this.level) {
|
||||||
case LogLevel.DEBUG:
|
case LogLevel.DEBUG:
|
||||||
return "DEBUG";
|
return " DEBUG";
|
||||||
case LogLevel.INFO:
|
case LogLevel.INFO:
|
||||||
return "INFO";
|
return " INFO";
|
||||||
case LogLevel.WARNING:
|
case LogLevel.WARNING:
|
||||||
return "WARNING";
|
return "WARNING";
|
||||||
case LogLevel.ERROR:
|
case LogLevel.ERROR:
|
||||||
return "ERROR";
|
return " ERROR";
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
49
plugin/src/views/logs-view.ts
Normal file
49
plugin/src/views/logs-view.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
import type { WorkspaceLeaf } from "obsidian";
|
||||||
|
import { ItemView } from "obsidian";
|
||||||
|
import { LogLevel, Logger } from "src/tracing/logger";
|
||||||
|
|
||||||
|
export class LogsView extends ItemView {
|
||||||
|
public static readonly TYPE = "logs-view";
|
||||||
|
public static readonly ICON = "logs";
|
||||||
|
|
||||||
|
private timer: NodeJS.Timer | null = null;
|
||||||
|
|
||||||
|
public constructor(leaf: WorkspaceLeaf) {
|
||||||
|
super(leaf);
|
||||||
|
this.icon = LogsView.ICON;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getViewType(): string {
|
||||||
|
return LogsView.TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getDisplayText(): string {
|
||||||
|
return "VaultLink logs";
|
||||||
|
}
|
||||||
|
|
||||||
|
public async onOpen(): Promise<void> {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
|
this.timer = setInterval(async () => this.updateView(), 250);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async onClose(): Promise<void> {
|
||||||
|
if (this.timer) {
|
||||||
|
clearInterval(this.timer);
|
||||||
|
this.timer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateView(): Promise<void> {
|
||||||
|
const container = this.containerEl.children[1];
|
||||||
|
container.empty();
|
||||||
|
|
||||||
|
container.createEl("h4", { text: "VaultLink logs" });
|
||||||
|
|
||||||
|
const messages = Logger.getInstance()
|
||||||
|
.getMessages(LogLevel.DEBUG)
|
||||||
|
.map((message) => message.toString())
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
container.createEl("pre", { text: messages });
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue