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 logging #40

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add logging #40

wants to merge 4 commits into from

Conversation

AbooMinister25
Copy link

No description provided.

Copy link
Contributor

@Robin5605 Robin5605 left a comment

Choose a reason for hiding this comment

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

@@ -39,16 +42,17 @@ def fetch_packages(*, pypi_client: PyPIServices) -> list[tuple[str, str]]:
def load_packages(packages: list[tuple[str, str]], *, http_client: Client, access_token: str) -> None:
"""Load all of the given packages into the Dragonfly API, using the given HTTP session and access token."""
payload = [{"name": name, "version": version} for name, version in packages]
logger.info("Loading packages: %s", payload)
Copy link
Contributor

Choose a reason for hiding this comment

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

Considering this will spit out 100 name/value pairs this should probably be debug

Suggested change
logger.info("Loading packages: %s", payload)
logger.debug("Loading packages: %s", payload)



def main(*, http_client: Client, pypi_client: PyPIServices) -> None:
"""Run the loader."""
access_token = get_access_token(http_client=http_client)

packages = fetch_packages(pypi_client=pypi_client)
logger.info("Fetched packages: %s", packages)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.info("Fetched packages: %s", packages)

I don't think we should log this because we log the same thing later on when we're loading the packages. We end up with 2 x 100 packages logged which is not ideal. We could also just do something like, fetched 100 packages maybe. doesn't really matter, up to you

Comment on lines +23 to +28
logger.debug("%s %s - Status %s", request.method, request.url, response.status_code)

try:
response.raise_for_status()
except HTTPError:
logger.exception("Response had a non 2xx status code")
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of the log level being based on the status code all in one log message. But I don't know if I like setting the level = logger.debug stuff that much, though. perhaps the logging library has a way to call a generic log method and pass in the level as a parameter? That would be much cleaner.

I just want to avoid the case where:

<blah blah>
GET /SOME URL - Status 500
<bunch of random logs>
EXCEPTION: Response had a non 2xx status code
<more blah blah>

wherein you need to go looking for which response had a non 2xx status code.

Suggested change
logger.debug("%s %s - Status %s", request.method, request.url, response.status_code)
try:
response.raise_for_status()
except HTTPError:
logger.exception("Response had a non 2xx status code")
try:
response.raise_for_status()
level = logger.debug
except HTTPError:
level = logger.exception
finally:
level("%s %s - Status %s", request.method, request.url, response.status_code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

2 participants