add unhandled exception logging
This commit is contained in:
parent
dddd444e4d
commit
1df3e08bee
35
myTS3.py
35
myTS3.py
|
@ -201,7 +201,7 @@ class TSbot:
|
|||
|
||||
def notifyAdmin(self):
|
||||
"""
|
||||
Ping every available admin
|
||||
Ping every available admin.
|
||||
"""
|
||||
|
||||
clients = self.bot.clientlist()
|
||||
|
@ -294,7 +294,7 @@ class TSbot:
|
|||
|
||||
def list(self, what, invkr_id):
|
||||
"""
|
||||
Message the invoker of the function either a list of channels or a list of clients
|
||||
Message the invoker of the function either a list of channels or a list of clients.
|
||||
"""
|
||||
|
||||
if what == "channel":
|
||||
|
@ -317,7 +317,7 @@ class TSbot:
|
|||
|
||||
def isqueryclient(self, cluid):
|
||||
"""
|
||||
Check if the given client-uid is a query client
|
||||
Check if the given client-uid is a query client.
|
||||
"""
|
||||
|
||||
# client = self.bot.clientlist(uid=uid)
|
||||
|
@ -332,7 +332,7 @@ class TSbot:
|
|||
|
||||
def isadmin(self, cldbid):
|
||||
"""
|
||||
Check if the given client-databaseid is an admin
|
||||
Check if the given client-databaseid is an admin.
|
||||
"""
|
||||
|
||||
groups = self.bot.servergroupsbyclientid(cldbid=cldbid)
|
||||
|
@ -351,6 +351,21 @@ class TSbot:
|
|||
|
||||
def lookupcommand(self, msg, invkr_id):
|
||||
"""
|
||||
Every message starting with '.' gets passed and evaluated in this function.
|
||||
|
||||
Command Parameter 1 Parameter 2
|
||||
---------------------------------------------------------
|
||||
.annoy target message
|
||||
.kickall message
|
||||
.test
|
||||
.btc / .eth
|
||||
.dot / .ada
|
||||
.list channel/clients
|
||||
.follow
|
||||
.rename nickname
|
||||
.stop / .quit / .q
|
||||
.pingall message
|
||||
.admin
|
||||
|
||||
"""
|
||||
|
||||
|
@ -424,13 +439,16 @@ class TSbot:
|
|||
self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=err)
|
||||
pass
|
||||
|
||||
elif command == ".admin":
|
||||
self.notifyAdmin()
|
||||
|
||||
else:
|
||||
err = f"Unknown Command: [{command}]"
|
||||
self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=err)
|
||||
|
||||
def printable_clientinfo(self, clid):
|
||||
"""
|
||||
|
||||
Generate printable clientinfo from clid.
|
||||
"""
|
||||
|
||||
usrd = {}
|
||||
|
@ -451,11 +469,11 @@ class TSbot:
|
|||
|
||||
def checkgrp(self):
|
||||
"""
|
||||
|
||||
Print all assigned groups for every connected client.
|
||||
"""
|
||||
|
||||
clients = self.bot.clientlist()
|
||||
clients_cldbid = [client["client_database_id"] for client in clients if client["client_type"] != "1"]
|
||||
# clients_cldbid = [client["client_database_id"] for client in clients if client["client_type"] != "1"]
|
||||
clients = self.bot.clientlist(groups=True)
|
||||
clients_groups = [client["client_servergroups"] for client in clients if client["client_type"] != "1"]
|
||||
|
||||
|
@ -468,6 +486,9 @@ def main():
|
|||
# Start logger
|
||||
log = util.setupLogger()
|
||||
|
||||
# Log unhandled exception
|
||||
sys.excepthook = util.unhandledException
|
||||
|
||||
# Load Dotenv
|
||||
dotenv_file = dotenv.find_dotenv()
|
||||
if not dotenv_file:
|
||||
|
|
10
util.py
10
util.py
|
@ -10,14 +10,24 @@ __status__ = "Development"
|
|||
|
||||
|
||||
# Default
|
||||
import sys
|
||||
import logging
|
||||
from datetime import date
|
||||
|
||||
|
||||
def unhandledException(exc_type, exc_value, exc_traceback):
|
||||
if issubclass(exc_type, KeyboardInterrupt):
|
||||
sys.__excepthook__(exc_type, exc_value, exc_traceback)
|
||||
return
|
||||
|
||||
log.critical("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
|
||||
|
||||
|
||||
def setupLogger():
|
||||
"""
|
||||
|
||||
"""
|
||||
global log
|
||||
log = logging.getLogger()
|
||||
now = date.today().strftime("%Y-%m-%d")
|
||||
handler = logging.FileHandler(f"myTS3_{now}.log", encoding="utf-8")
|
||||
|
|
Loading…
Reference in New Issue