This repository has been archived on 2022-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
irreligious/src/logging/DebugLogger.ts

30 lines
693 B
TypeScript
Raw Normal View History

2021-08-21 21:06:29 -05:00
class DebugLogger implements ILogger {
2021-09-05 14:45:37 -05:00
private readonly _container: HTMLElement;
2021-08-21 21:06:29 -05:00
constructor(container: HTMLElement) {
2021-08-21 21:06:29 -05:00
this._container = container;
}
public msg(text: string): void {
2021-09-06 08:51:41 -05:00
this._doMsg(text, true);
}
public unsafeMsg(text: string): void {
2021-09-06 08:51:41 -05:00
this._doMsg(text, false);
}
private _doMsg(text: string, safe: boolean): void {
2021-09-06 08:51:41 -05:00
const el = document.createElement('p');
if (safe) {
el.innerText = text;
} else {
el.innerHTML = text;
}
this._container.appendChild(el);
2021-09-05 14:45:37 -05:00
if (this._container.parentElement !== null) {
this._container.parentElement.scrollTop =
this._container.parentElement.scrollHeight;
}
2021-08-21 21:06:29 -05:00
}
}