File size: 706 Bytes
2b8ca65
 
 
 
68fc3c9
2b8ca65
 
 
 
 
 
 
 
 
 
 
 
 
 
68fc3c9
2b8ca65
 
 
 
 
 
 
 
 
 
 
 
 
68fc3c9
 
2b8ca65
68fc3c9
 
 
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
from __future__ import annotations

from datetime import datetime, timezone

LINES: list[str] = []


def ts() -> str:
    return datetime.now(timezone.utc).isoformat(timespec="seconds")


def log(level: str, msg: str) -> None:
    html = {
        "INFO": "dodgerblue",
        "WARN": "goldenrod",
        "ERR": "crimson",
    }
    c = html.get(level)
    tag = f"<span style=\"color:{c}\">{level}</span>" if c else level
    LINES.append(f"[{ts()}] {tag}: {msg}")


def info(msg: str) -> None:
    log("INFO", msg)


def warn(msg: str) -> None:
    log("WARN", msg)


def error(msg: str) -> None:
    log("ERR", msg)

def clear() -> None:
    LINES.clear()


def lines() -> list[str]:
    return LINES