Skip to content

Commit

Permalink
Improve logging (#72)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AndyRae authored Feb 4, 2025
1 parent 90f6465 commit c160765
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/hutch_bunny/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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}")

Expand Down
11 changes: 9 additions & 2 deletions src/hutch_bunny/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from os import environ
from dotenv import load_dotenv
from importlib.metadata import version

load_dotenv()

Expand All @@ -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"
Expand All @@ -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}")
Expand All @@ -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}")
logger.debug(f" COLLECTION_ID: {COLLECTION_ID}")
1 change: 1 addition & 0 deletions src/hutch_bunny/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit c160765

Please sign in to comment.