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

Update API entrypoint and add logger configuration #62

Merged
merged 2 commits into from
Jan 13, 2024
Merged

Conversation

critch646
Copy link
Collaborator

Problem

The API has no logging for developers to use.

Solution

  • Added logger to FastAPI main entry point.
  • Created api/logger_config.yaml with configurations for formatters and loggers
  • Updated docker-compose.yaml services api and apitarget commands to use api/logger_config.yaml
  • Added logger to api/models/patient_encounter.py and completed TODO

Ticket URL

https://mediform.atlassian.net/browse/MEDI-15

Documentation

N/A

Tests Run

  • Tested locally. Rebuilt api image and spun up container.
  • Checked logs and logger uses new format.
  • For testing purposes, had line that logged on loading patient_encounter.py and line was represented in logs. Line removed for production.

@critch646 critch646 requested a review from MadelaineJ January 13, 2024 00:15
Copy link
Collaborator

@MadelaineJ MadelaineJ left a comment

Choose a reason for hiding this comment

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

Look good. Just a couple questions from me.

@@ -5,10 +5,13 @@

from fastapi import Depends, FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
import logging
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason we need these lines in app.py if we're not logging anything from the file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe it is needed because this is the entry point of the app? Did you test without it and it failed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed the entry point logger, which works with the customer format elsewhere. Since this log config is passed to uvicorn at the start the logger inherits the config in different modules in the API.

app/api/logger_config.yaml Show resolved Hide resolved
@@ -102,8 +104,7 @@ def get_latest_patient_encounter_by_patient_rfid(
standalone_argon2.exceptions.VerificationError,
standalone_argon2.exceptions.InvalidHash,
) as e:
# TODO: Should do something intelligent like logging this.
continue
logger.error(e)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I looked into that flag and I think it is worth putting in. I added it in the latest commit.

@critch646 critch646 merged commit 5ab1756 into main Jan 13, 2024
@critch646 critch646 deleted the zeke/dev/api_log branch January 13, 2024 23:15
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