Refactor logging

This commit is contained in:
Oliver Hartmann 2021-03-20 21:31:16 +01:00
parent a321824fda
commit 965eb3be48
4 changed files with 14 additions and 5 deletions

View File

@ -1,7 +1,9 @@
from src import gui from src import gui
from src import trader from src import trader
from src import config from src import config
from src import data from src import sendkeys
from src.data import compile_regex
from src.data import log
from threading import Thread from threading import Thread
from argparse import Namespace, ArgumentParser from argparse import Namespace, ArgumentParser
@ -17,9 +19,12 @@ def setup_args() -> Namespace:
if __name__ == "__main__": if __name__ == "__main__":
args = setup_args() args = setup_args()
log.debug(f'Read config from "{args.configfile}"')
conf = config.read_config(args.configfile) conf = config.read_config(args.configfile)
data.compile_regex(conf) log.debug('Compiling regex')
compile_regex(conf)
app = gui.Gui() app = gui.Gui()
my_thread = Thread(target=trader.read_log, args=(conf['General']['log_file'], app)) my_thread = Thread(target=trader.read_log, args=(conf['General']['log_file'], app))
log.debug(f'Starting reader thread for "{conf["General"]["log_file"]}"')
my_thread.start() my_thread.start()
app.mainloop() app.mainloop()

View File

@ -12,7 +12,7 @@ re_log = re.compile(
r'(?P<channel>[#@%$&]?)(?P<ToFrom>To|From)?\s?(?P<guild><\S+>)? ?(?P<user>[^:]+): (?P<message>.*)' r'(?P<channel>[#@%$&]?)(?P<ToFrom>To|From)?\s?(?P<guild><\S+>)? ?(?P<user>[^:]+): (?P<message>.*)'
) )
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s:: %(message)s')
def compile_regex(conf: dict): def compile_regex(conf: dict):
@ -58,6 +58,9 @@ class Trade():
self.col = col self.col = col
self.league = league self.league = league
def __str__(self) -> str:
return f'Trade: {self.item} for {self.amount} {self.currency} in {self.tab} ({self.row}/{self.col}) in {self.league} league'
class Message(): class Message():
def __init__(self, def __init__(self,
@ -96,7 +99,7 @@ class Message():
result.group('ToFrom')) result.group('ToFrom'))
def __str__(self) -> str: def __str__(self) -> str:
text = f'{self.date} - {self.channel.name}: ' text = f'Message: {self.date} - {self.channel.name}: '
if self.to_from: if self.to_from:
text = text + f'{self.to_from} ' text = text + f'{self.to_from} '
if self.guild: if self.guild:

View File

@ -10,7 +10,7 @@ def send_text(text: str) -> None:
try: try:
app.connect(title=config.conf['General']['poe_window_title']) app.connect(title=config.conf['General']['poe_window_title'])
except ElementNotFoundError: except ElementNotFoundError:
data.log.warning(f'Title {config.conf["General"]["poe_window_title"]} not found') data.log.warning(f'Window Title "{config.conf["General"]["poe_window_title"]}" not found')
return return
win = app.window(title_re=config.conf['General']['poe_window_title']) win = app.window(title_re=config.conf['General']['poe_window_title'])
text = escape_mods(text) text = escape_mods(text)

View File

@ -11,6 +11,7 @@ def read_log(logfile: str, app: gui.Gui) -> None:
message = Message.from_text(line) message = Message.from_text(line)
log.debug(message) log.debug(message)
if message and message.trade and message.to_from == 'From': if message and message.trade and message.to_from == 'From':
log.debug(message.trade)
app.add_tab(30, message) app.add_tab(30, message)