-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.mjs
48 lines (37 loc) · 1001 Bytes
/
log.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Log {
#container_element;
#createElement(text) {
const element = document.createElement("DIV");
element.innerText = text;
return element;
}
get attached() {
return (this.#container_element !== undefined);
}
attachToContainer(element) {
this.#container_element = element;
this.clear();
}
append(text) {
if(this.attached === false) return;
this.#container_element.append(this.#createElement(text));
}
appendWarning(text) {
if(this.attached === false) return;
const element = this.#createElement(text);
element.classList.add("warning");
element.innerText = `⚠️ ${element.innerText}`;
this.#container_element.append(element);
}
appendError(text) {
if(this.attached === false) return;
const element = this.#createElement(text);
element.classList.add("error");
element.innerText = `🛑 ${element.innerText}`;
this.#container_element.append(element);
}
clear() {
this.#container_element.innerHTML = "";
}
}
export default new Log();