100th commit! (Add timestamps to logs, and fix long-standing bug with log to err)
This commit is contained in:
parent
6626781dff
commit
f876ea3ab1
3 changed files with 12 additions and 6 deletions
2
core.py
2
core.py
|
@ -1,9 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
from os import system
|
||||
from time import sleep
|
||||
from sys import argv as args
|
||||
from threading import Thread
|
||||
from datetime import datetime as dt
|
||||
from logs import log
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
#!/usr/bin/python3
|
||||
from bot import bot
|
||||
from sys import argv as args
|
||||
from traceback import format_exc
|
||||
from logs import log
|
||||
|
||||
server = args[1] if args else "UNSTABLE BOT MODE"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
instance = bot(server)
|
||||
try:
|
||||
instance.mainloop()
|
||||
except Exception:
|
||||
Err = format_exc()
|
||||
for line in Err.split("\n"):
|
||||
log(line, server, "CRASH")
|
||||
exit(-1)
|
||||
|
|
6
logs.py
6
logs.py
|
@ -6,14 +6,14 @@ from sys import stdout, stderr
|
|||
def log(
|
||||
message: str, origin: str = "Unknown", level: str = "LOG", time: dt = "now"
|
||||
) -> None:
|
||||
if level == "EXIT":
|
||||
if level in ["EXIT", "CRASH"]:
|
||||
stream = stderr
|
||||
else:
|
||||
stream = stdout
|
||||
if time == "now":
|
||||
time = dt.now()
|
||||
if not "\n" in message:
|
||||
print(f"[{level}][{origin}][{time}] {message}")
|
||||
print(f"[{level}][{origin}][{time}] {message}", file=stream)
|
||||
else:
|
||||
for line in message.split("\n"):
|
||||
print(f"[{level}][{origin}][{time}] {line}")
|
||||
print(f"[{level}][{origin}][{time}] {line}", file=stream)
|
||||
|
|
Loading…
Reference in a new issue