File size: 436 Bytes
be8ab52 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import datetime
LOG_FILE = "runtime.log"
ERROR_FILE = "errors.log"
def log(message: str, level: str = "INFO"):
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
line = f"[{ts}] [{level}] {message}"
print(line)
with open(LOG_FILE, "a", encoding="utf-8") as f:
f.write(line + "\n")
if level == "ERROR":
with open(ERROR_FILE, "a", encoding="utf-8") as f:
f.write(line + "\n")
|