Skip to content

Commit

Permalink
Merge pull request #144 from Chia-Network/feat/version-in-log
Browse files Browse the repository at this point in the history
feat: add version to log output
  • Loading branch information
MichaelTaylor3D authored Nov 30, 2023
2 parents f540df3 + b784ef8 commit c5efce9
Show file tree
Hide file tree
Showing 4 changed files with 2,518 additions and 2,498 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",
}
)
Loading

0 comments on commit c5efce9

Please sign in to comment.