From a112885f37b46a6e4c89ad4c52ab2d3f9aa180d0 Mon Sep 17 00:00:00 2001 From: DnlRKorn <6885702+DnlRKorn@users.noreply.github.com> Date: Wed, 31 Jul 2024 17:52:14 -0400 Subject: [PATCH] Update sql_implementation.py to include sqlachemy output in debug logging. (#782) * Update sql_implementation.py to include sqlachemy output in debug logging. The current logging scheme directly prints the query as rendered by str(q); the following is the output from logging.info(f"ECA query: {q}") in function _equivalent_class_relationships. INFO:root:ECA query: SELECT statements.subject AS statements_subject, statements.predicate AS statements_predicate, statements.object AS statements_object FROM statements WHERE statements.predicate = ? AND statements.object IN (__[POSTCOMPILE_object_1]) AND statements.object IN (SELECT class_node.id FROM class_node) With this change, when running at logging level DEBUG, anytime a query is executed sqlachemy will also writes it's logging output, which is the following: INFO:sqlalchemy.engine.Engine:SELECT statements.subject AS statements_subject, statements.predicate AS statements_predicate, statements.object AS statements_object FROM statements WHERE statements.predicate = ? AND statements.object IN (?) AND statements.object IN (SELECT class_node.id FROM class_node) INFO:sqlalchemy.engine.Engine:[generated in 0.00023s] ('owl:equivalentClass', 'MONDO:0000550') In the Sqlalchemy logging, the ambiguous term "(__[POSTCOMPILE_object_1])" isn't stated and instead replaced with a query parameter, and the query parameters are outputted on a second line. * Update sql_implementation.py Corrected lint errors --- src/oaklib/implementations/sqldb/sql_implementation.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/oaklib/implementations/sqldb/sql_implementation.py b/src/oaklib/implementations/sqldb/sql_implementation.py index acdaa9dfd..3b839c5c0 100644 --- a/src/oaklib/implementations/sqldb/sql_implementation.py +++ b/src/oaklib/implementations/sqldb/sql_implementation.py @@ -365,6 +365,11 @@ def __post_init__(self): logging.info(f"Locator, post-processed: {locator}") self.engine = create_engine(locator) + if(logging.root.level <= logging.DEBUG): + #If oaklib is running at DEBUG level logging; record all queries from sqlachemy on execution. + #This line is equivalent to create_engine(locator,echo=True) + logging.getLogger('sqlalchemy.engine.Engine').setLevel(logging.INFO) + @property def session(self): if self._session is None: