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

class DebugLogger implements ILogger {
private readonly _container: HTMLElement;
constructor(container: HTMLElement) {
this._container = container;
}
public msg(text: string): void {
this._doMsg(text, true);
}
public unsafeMsg(text: string): void {
this._doMsg(text, false);
}
private _doMsg(text: string, safe: boolean): void {
const el = document.createElement('p');
if (safe) {
el.innerText = text;
} else {
el.innerHTML = text;
}
this._container.appendChild(el);
if (this._container.parentElement !== null) {
this._container.parentElement.scrollTop =
this._container.parentElement.scrollHeight;
}
}
}