From 3972f3d63d4ea3c45d36ce74a3bf28f5dc033602 Mon Sep 17 00:00:00 2001 From: Eduard Kaverinskyi Date: Sat, 18 Jan 2025 17:52:52 +0100 Subject: [PATCH] db/database.py: improve database logs Signed-off-by: Eduard Kaverinskyi --- whois/data/db/database.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/whois/data/db/database.py b/whois/data/db/database.py index 7b5f688..e3359fe 100644 --- a/whois/data/db/database.py +++ b/whois/data/db/database.py @@ -24,6 +24,7 @@ def __init__(self, db_url: str = None): force=True, ) + self.logger.debug(f'Creating engine for "{db_url}"') self.engine = db.create_engine(db_url) self.metadata = db.MetaData() self.connection = None @@ -37,23 +38,23 @@ def is_connected(self) -> bool: return self.connection is not None def connect(self) -> None: - self.logger.info(f"Connect to the database for {self.db_name}") + self.logger.info(f'Connect to the database for "{self.db_name}"') self.connection = self.engine.connect() def disconnect(self) -> None: - self.logger.info(f"Disconnect to the database for {self.db_name}") + self.logger.info(f'Disconnect to the database for "{self.db_name}"') if not self.connection: raise RuntimeError("Cannot close database connection - already closed") self.connection.close() def create_db(self) -> None: """Ensure that the database exists with given schema.""" - self.logger.info(f"Create database {self.db_name}") + self.logger.info(f'Create database "{self.db_name}"') Base.metadata.create_all(self.engine) def drop(self) -> None: """WARNING: Drops the entire database.""" - self.logger.warning(f"Drop database {self.db_name}") + self.logger.warning(f'Drop database "{self.db_name}"') if not self.is_connected: self.connect() Base.metadata.drop_all(self.engine)