Skip to content

Commit

Permalink
feat: add version to log output
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Nov 30, 2023
1 parent f540df3 commit 3eceec2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/api/v1/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")

Expand Down
15 changes: 11 additions & 4 deletions app/logger.py
Original file line number Diff line number Diff line change
@@ -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",
)

Expand All @@ -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",
}
)
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"Chia Network Inc <[email protected]>"]
Expand All @@ -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"
Expand Down

0 comments on commit 3eceec2

Please sign in to comment.