diff --git a/conservancy_beancount/rtutil.py b/conservancy_beancount/rtutil.py index 8e98ca9..28a87ef 100644 --- a/conservancy_beancount/rtutil.py +++ b/conservancy_beancount/rtutil.py @@ -15,6 +15,7 @@ # along with this program. If not, see . import functools +import logging import mimetypes import os import re @@ -78,6 +79,7 @@ class RTLinkCache(_LinkCache): url TEXT NOT NULL, PRIMARY KEY (ticket_id, attachment_id) )""" + logger = logging.getLogger('conservancy_beancount.rtutil.RTLinkCache') @classmethod def setup(cls, cache_path: Path) -> Optional[sqlite3.Connection]: @@ -89,6 +91,7 @@ class RTLinkCache(_LinkCache): have_data = cursor.fetchone() is not None except sqlite3.OperationalError: # If we couldn't get this far, sqlite provides no benefit. + cls.logger.debug("setup: error loading %s", cache_path, exc_info=True) return None try: # There shouldn't be any records where url is NULL, so running this @@ -96,12 +99,14 @@ class RTLinkCache(_LinkCache): # can write to the database and it enforces database integrity. cursor.execute('DELETE FROM RTLinkCache WHERE url IS NULL') except sqlite3.OperationalError: + cls.logger.debug("setup: error writing %s", cache_path, exc_info=True) can_write = False else: can_write = True if not (can_write or have_data): # If there's nothing to read and no way to write, sqlite provides # no benefit. + cls.logger.debug("setup: not using %s: nothing to read or write", cache_path) return None elif not can_write: # Set up an in-memory database that we can write to, seeded with @@ -119,7 +124,12 @@ class RTLinkCache(_LinkCache): except sqlite3.OperationalError as error: # We're back to the case of having nothing to read and no way # to write. + cls.logger.debug("setup: error loading %s into memory", cache_path, exc_info=True) return None + else: + cls.logger.debug("setup: loaded %s into memory", cache_path) + else: + cls.logger.debug("setup: caching at %s", cache_path) cursor.close() db.commit() return db