Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logger to seeder. #82

Merged
merged 1 commit into from
Feb 1, 2024
Merged

Add logger to seeder. #82

merged 1 commit into from
Feb 1, 2024

Conversation

critch646
Copy link
Collaborator

Problem
Seeder had no logger. Uses print statements in exceptions.

Solution

  • Added logger to seed_database.py
  • Modified Dockerfile.seed to copy API logger config
  • Updated exceptions to send errors to logger instead of print

Ticket URL
https://mediform.atlassian.net/browse/MEDI-39

Documentation
N/A

Tests Run

  • Built and run seeder using docker compose up --build seeder

Problem
Seeder had no logger. Uses print statements in exceptions.

Solution
- Added logger to `seed_database.py`
- Modified `Dockerfile.seed` to copy API logger config
- Updated exceptions to send errors to logger instead of print

Ticket URL
https://mediform.atlassian.net/browse/MEDI-39

Documentation
N/A

Tests Run
- Built and run seeder using `docker compose up --build seeder`
@critch646 critch646 requested a review from MadelaineJ January 30, 2024 23:51
@@ -83,7 +93,7 @@ def create_user(user: Dict, db: Session) -> User:
print(e)
db.rollback()
db.flush()
print(f"User {user_obj.email} already exists")
logger.error("Error adding user to database.", exc_info=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changed to not specify the error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above that:

# Create user in database if it doesn't exist
user_obj = db.query(User).filter(User.email == user["email"]).first()
if user_obj:
print(f"User {user_obj.email} already exists")
return user_obj

It already checks if the user exists, so the error is probably something else that the stack trace will reveal using exc_info=True.

@@ -176,8 +186,7 @@ def seed_database():
print(e)
db.rollback()
db.flush()
print(f"ERROR creating patient encounter: {patient_encounter}")
print(f"\tERROR: {e}")
logger.error(f"Error adding patient encounter to db.", exc_info=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stack trace?

@critch646 critch646 merged commit 69aed8e into main Feb 1, 2024
1 check passed
@critch646 critch646 deleted the zeke/dev/seder-logger branch February 1, 2024 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants