From: Edward Delaporte Date: Wed, 8 Apr 2026 22:37:02 +0000 (-0500) Subject: Improve debugging X-Git-Url: https://us-delaporte.pagekite.me/gitweb/matrix-goal-bot.git/commitdiff_plain/6c0064a26d3facaea4590bc9d02558e6e6fdb937?ds=sidebyside Improve debugging --- diff --git a/Makefile b/Makefile index a73de66..2eb2952 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: serve test strict +.PHONY: serve tail test strict MODULE=goals @@ -13,6 +13,9 @@ clean: rm -rf .venv rm session.txt # Reset session +tail: + tail -f matrix-goal-bot.log + test: .venv .venv/bin/pip install .[test] .venv/bin/mypy -m $(MODULE) diff --git a/app.py b/app.py index d9254b8..a34d982 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,15 @@ +import logging import os from matrix_goal_bot.bot import GoalBot +logging.basicConfig(filename='matrix-goal-bot.log', encoding='utf-8', level=logging.DEBUG) +logging.getLogger('nio').setLevel(logging.WARNING) +logging.getLogger('asyncio').setLevel(logging.WARNING) + +logger = logging.getLogger(__name__) +logger.info("Starting goal bot...") + kwargs = {} # How to connect to Matrix kwargs['matrix_server'] = os.environ.get('MATRIX_SERVER') @@ -11,11 +19,16 @@ kwargs['bot_pwd'] = os.environ.get('MATRIX_BOT_PWD') # Prefix to listen for kwargs['bot_prefix'] = os.environ.get('MATRIX_BOT_PREFIX', '!chore') +logger.info(f'Goal bot will connect to {kwargs["matrix_server"]} as {kwargs["bot_name"]}') + # Where to store data DATA_DIR = os.environ.get('MATRIX_DATA_DIR', '') DB_FILE = os.environ.get('MATRIX_DB_FILE', 'goal.db') kwargs['db_file'] = os.path.join(DATA_DIR, DB_FILE) +logger.info(f'Goal bot will store data at {kwargs["db_file"]}') + + goal_bot = GoalBot(**kwargs) @goal_bot.bot.listener.on_message_event diff --git a/matrix_goal_bot/bot.py b/matrix_goal_bot/bot.py index dce0f73..4046eeb 100644 --- a/matrix_goal_bot/bot.py +++ b/matrix_goal_bot/bot.py @@ -42,8 +42,6 @@ def today(): return dt.now().strftime(DATE_FORMAT) logger = logging.getLogger(__name__) -logging.basicConfig(filename='matrix-goal-bot.log', encoding='utf-8', level=logging.DEBUG) -logging.getLogger('nio').setLevel(logging.WARNING) snark = [ 'Ye cannot get ye flask.', @@ -69,9 +67,11 @@ class GoalBot(): self.data = Data(db_file) def run(self): + logger.debug('Running goal bot...') self.bot.run() async def handle_message(self, room, message): + logger.debug(f'Message: {message}') match = botlib.MessageMatch(room, message, self.bot, self.prefix) if not match.is_not_from_this_bot() and match.prefix(): diff --git a/matrix_goal_bot/db.py b/matrix_goal_bot/db.py index 6a73021..bc8cdbc 100644 --- a/matrix_goal_bot/db.py +++ b/matrix_goal_bot/db.py @@ -4,6 +4,7 @@ from datetime import datetime as dt from sqlmodel import Field, Session, SQLModel, create_engine, select, text, Relationship +logger = logging.getLogger(__name__) DATE_FORMAT = '%Y-%m-%d' @@ -11,10 +12,6 @@ def today(): return dt.now().strftime(DATE_FORMAT) -logger = logging.getLogger(__name__) -logging.basicConfig(filename='goals.log', encoding='utf-8', level=logging.DEBUG) - - class Vision(SQLModel, table=True): id: int | None = Field(default=None, primary_key=True) name: str = Field(default=None, unique=True) @@ -70,7 +67,7 @@ def pretty_print(goal, tasks): class Data(): def __init__(self, db_file=None): if not db_file: - db_file = os.path.join(os.environ.get('MATRIX_DATA_DIR', ''), 'goals.db') + db_file = os.path.join(os.environ.get('MATRIX_DATA_DIR', ''), 'goal.db') self.file = db_file self.engine = self.get_engine()