From 3eceec2cfb5953664c980735acba44800e747b0f Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Thu, 30 Nov 2023 11:00:50 -0500 Subject: [PATCH] feat: add version to log output --- app/api/v1/cron.py | 5 +++-- app/logger.py | 15 +++++++++++---- pyproject.toml | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/api/v1/cron.py b/app/api/v1/cron.py index 21132cf..c78b2c3 100644 --- a/app/api/v1/cron.py +++ b/app/api/v1/cron.py @@ -130,8 +130,9 @@ async def _scan_token_activity( db_crud.batch_insert_ignore_activity(activities) logger.info(f"Activities for {org_name} and asset id: {key} added to the database.") - except json.JSONDecodeError as e: - logger.error(f"Failed to parse JSON for key {key} in organization {org_name}: {str(e)}") + # This is causing logging for benign errors, so commenting out for now + # except json.JSONDecodeError as e: + # logger.error(f"Failed to parse JSON for key {key} in organization {org_name}: {str(e)}") except Exception as e: logger.error(f"An error occurred for organization {org_name} under key {key}: {str(e)}") diff --git a/app/logger.py b/app/logger.py index 5caddf3..ce50155 100644 --- a/app/logger.py +++ b/app/logger.py @@ -1,15 +1,22 @@ from __future__ import annotations import logging - import uvicorn - +import toml from app.config import settings +# Parse pyproject.toml to get the version +with open('pyproject.toml', 'r') as toml_file: + pyproject = toml.load(toml_file) +version = pyproject['tool']['poetry']['version'] + +# Define the log format with version +log_format = f"%(asctime)s,%(msecs)d {version} %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s" + logging.basicConfig( level=logging.INFO, filename=settings.LOG_PATH, - format="%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s", + format=log_format, filemode="w", ) @@ -18,7 +25,7 @@ log_config["formatters"]["default"].update( { - "fmt": "%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s", + "fmt": log_format, "datefmt": "%Y-%m-%d:%H:%M:%S", } ) diff --git a/pyproject.toml b/pyproject.toml index b754df6..a8dd8d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "Chia Climate Token Driver" -version = "1.0.36" +version = "1.0.37" description = "https://github.com/Chia-Network/climate-token-driver" authors = ["Harry Hsu ", "Chia Network Inc "] @@ -15,6 +15,7 @@ python = "^3.10" #chia-blockchain = { path = "./chia-blockchain", develop = true } fastapi = "^0.83.0" uvicorn = "^0.18.3" +toml = "^0.10.2" SQLAlchemy = "^1.4.41" requests = "^2.28.1" fastapi-utils = "^0.2.1"