From c160765e195efe19506356ff4529391227b3fd55 Mon Sep 17 00:00:00 2001 From: Andy Rae Date: Tue, 4 Feb 2025 10:33:51 +0000 Subject: [PATCH] Improve logging (#72) * Add availability json * Update gitinogre * Add omop-lite * Add contributing * Update gitignore * Log results * Fix typed settings * Add main method and VSCode debug configurations * Add distribution query test configuration * Add version logging * Bump version to 1.0.0-alpha.3 --- pyproject.toml | 2 +- src/hutch_bunny/cli.py | 3 +++ src/hutch_bunny/core/settings.py | 11 +++++++++-- src/hutch_bunny/daemon.py | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 289df48..668ebca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "hutch-bunny" -version = "1.0.0-alpha.2" +version = "1.0.0-alpha.3" description = "A Cohort Discovery Task API worker" license = { text = "MIT License" } readme = "README.md" diff --git a/src/hutch_bunny/cli.py b/src/hutch_bunny/cli.py index ca77227..a143dc8 100644 --- a/src/hutch_bunny/cli.py +++ b/src/hutch_bunny/cli.py @@ -5,6 +5,7 @@ from hutch_bunny.core.parser import parser from hutch_bunny.core.logger import logger from hutch_bunny.core.setting_database import setting_database +import hutch_bunny.core.settings as settings def save_to_output(result: RquestResult, destination: str) -> None: @@ -29,6 +30,7 @@ def save_to_output(result: RquestResult, destination: str) -> None: def main() -> None: + settings.log_settings() # Setting database connection db_manager = setting_database(logger=logger) # Bunny passed args. @@ -41,6 +43,7 @@ def main() -> None: result = execute_query( query_dict, results_modifier, logger=logger, db_manager=db_manager ) + logger.debug(f"Results: {result.to_dict()}") save_to_output(result, args.output) logger.info(f"Saved results to {args.output}") diff --git a/src/hutch_bunny/core/settings.py b/src/hutch_bunny/core/settings.py index 6ca2304..4ed9cdc 100644 --- a/src/hutch_bunny/core/settings.py +++ b/src/hutch_bunny/core/settings.py @@ -1,6 +1,7 @@ import logging from os import environ from dotenv import load_dotenv +from importlib.metadata import version load_dotenv() @@ -23,7 +24,7 @@ # Logging configuration LOGGER_NAME = "hutch" -LOGGER_LEVEL = logging.getLevelNamesMapping().get(environ.get("BUNNY_LOGGER_LEVEL"),"INFO") +LOGGER_LEVEL = logging.getLevelNamesMapping().get(environ.get("BUNNY_LOGGER_LEVEL") or "INFO", "INFO") BACKUP_LOGGER_NAME = "backup" MSG_FORMAT = "%(levelname)s - %(asctime)s - %(message)s" DATE_FORMAT = "%d-%b-%y %H:%M:%S" @@ -49,10 +50,16 @@ COLLECTION_ID = environ.get("COLLECTION_ID") +try: + BUNNY_VERSION = version("hutch_bunny") +except Exception: + BUNNY_VERSION = "unknown" + def log_settings(): from hutch_bunny.core.logger import logger #This is here to prevent a circular import logger.debug("Running with settings:") + logger.debug(f" BUNNY VERSION: {BUNNY_VERSION}") logger.debug(f" DATASOURCE_USE_TRINO: {DATASOURCE_USE_TRINO}") logger.debug(f" DEFAULT_POSTGRES_DRIVER: {DEFAULT_POSTGRES_DRIVER}") logger.debug(f" DEFAULT_DB_DRIVER: {DEFAULT_DB_DRIVER}") @@ -69,4 +76,4 @@ def log_settings(): logger.debug(f" ROUNDING_TARGET: {ROUNDING_TARGET}") logger.debug(f" POLLING_INTERVAL_DEFAULT: {POLLING_INTERVAL_DEFAULT}") logger.debug(f" POLLING_INTERVAL: {POLLING_INTERVAL}") - logger.debug(f" COLLECTION_ID: {COLLECTION_ID}") \ No newline at end of file + logger.debug(f" COLLECTION_ID: {COLLECTION_ID}") diff --git a/src/hutch_bunny/daemon.py b/src/hutch_bunny/daemon.py index b959d37..85e00f6 100644 --- a/src/hutch_bunny/daemon.py +++ b/src/hutch_bunny/daemon.py @@ -41,6 +41,7 @@ def main() -> None: logger=logger, db_manager=db_manager, ) + logger.debug(f"Result: {result.to_dict()}") # Check the payload shape if not isinstance(result, RquestResult): raise TypeError("Payload does not match RQuest result schema.")