forked from Firepup650/FireBot
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
|
#!/usr/bin/python3
|
||||||
from os import system
|
from os import system
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from sys import argv as args
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from datetime import datetime as dt
|
|
||||||
from logs import log
|
from logs import log
|
||||||
|
|
||||||
|
|
||||||
|
|
10
ircbot.py
10
ircbot.py
|
@ -1,10 +1,18 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from bot import bot
|
from bot import bot
|
||||||
from sys import argv as args
|
from sys import argv as args
|
||||||
|
from traceback import format_exc
|
||||||
|
from logs import log
|
||||||
|
|
||||||
server = args[1] if args else "UNSTABLE BOT MODE"
|
server = args[1] if args else "UNSTABLE BOT MODE"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
instance = bot(server)
|
instance = bot(server)
|
||||||
instance.mainloop()
|
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(
|
def log(
|
||||||
message: str, origin: str = "Unknown", level: str = "LOG", time: dt = "now"
|
message: str, origin: str = "Unknown", level: str = "LOG", time: dt = "now"
|
||||||
) -> None:
|
) -> None:
|
||||||
if level == "EXIT":
|
if level in ["EXIT", "CRASH"]:
|
||||||
stream = stderr
|
stream = stderr
|
||||||
else:
|
else:
|
||||||
stream = stdout
|
stream = stdout
|
||||||
if time == "now":
|
if time == "now":
|
||||||
time = dt.now()
|
time = dt.now()
|
||||||
if not "\n" in message:
|
if not "\n" in message:
|
||||||
print(f"[{level}][{origin}][{time}] {message}")
|
print(f"[{level}][{origin}][{time}] {message}", file=stream)
|
||||||
else:
|
else:
|
||||||
for line in message.split("\n"):
|
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