Improved db context logging

This commit is contained in:
Sven Heidemann 2021-11-30 15:18:07 +01:00
parent 61101eb576
commit 1d4a6c3e3b

View File

@ -15,7 +15,13 @@ class DBContext(DatabaseContext):
def connect(self, database_settings: DatabaseSettings):
try:
self._logger.debug(__name__, "Connecting to database")
super(DBContext, self).connect(database_settings)
self._db.connect(database_settings)
for table in self._tables:
self._logger.debug(__name__, f"Create table if not exists: {table}")
self._logger.trace(__name__, f'Send SQL command: {table.get_create_string()}')
self._db.cursor.execute(table.get_create_string())
self.save_changes()
self._logger.info(__name__, "Connected to database")
except Exception as e:
self._logger.fatal(__name__, "Connecting to database failed", e)