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

Move logging setup outside lifespan and db initialisation logic #309

Merged
merged 5 commits into from
Jun 4, 2024

Conversation

northwestwitch
Copy link
Member

@northwestwitch northwestwitch commented Jun 3, 2024

Description

It's not a fix for #308, but setting up logging should be outside the function for the database setup

  • Moved logging setup out of app lifespan and db initialisation logic

How to test

  • Deploy on stage and make sure that the app starts and prints logging messages

Review

  • Tests executed by CR
  • "Merge and deploy" approved by HS

This version is a

  • MAJOR - when you make incompatible API changes
  • MINOR - when you add functionality in a backwards compatible manner
  • PATCH - when you make backwards compatible bug fixes or documentation/instructions

@northwestwitch northwestwitch changed the title Move logging setup outside lifespan and db initialisation logi Move logging setup outside lifespan and db initialisation logic Jun 3, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jun 3, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.40%. Comparing base (4c8ac1b) to head (c80d6d7).
Report is 1 commits behind head on main.

Files Patch % Lines
src/chanjo2/logger.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #309   +/-   ##
=======================================
  Coverage   94.40%   94.40%           
=======================================
  Files          35       36    +1     
  Lines        2002     2003    +1     
=======================================
+ Hits         1890     1891    +1     
  Misses        112      112           
Flag Coverage Δ
unittests 94.40% <87.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -56,15 +65,6 @@ def configure_static(app):


async def startup_db():
# Configure logging
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a bad place for the logging setup anyway, being a function that starts the database

@northwestwitch
Copy link
Member Author

Tested on stage: 🆗

image

Copy link
Contributor

@henrikstranneheim henrikstranneheim left a comment

Choose a reason for hiding this comment

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

Good catch, 👍

Comment on lines 27 to 35
console_formatter = uvicorn.logging.ColourizedFormatter(
"{levelprefix} {asctime} : {message}", style="{", use_colors=True
)
if LOG.handlers:
LOG.handlers[0].setFormatter(console_formatter)
else:
logging.basicConfig()


Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to have this in a function in a separate module from main to keep it as free from logic as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, good suggestion! 👍🏻

@@ -23,6 +23,15 @@
(overview.router, "overview"),
]

# Configure logging
console_formatter = uvicorn.logging.ColourizedFormatter(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an informative type hint for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's an instance of the class uvicorn.logging.ColourizedFormatter. I think it's redundant to write it down

src/chanjo2/main.py Outdated Show resolved Hide resolved
Copy link

sonarqubecloud bot commented Jun 4, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@northwestwitch northwestwitch merged commit 3524601 into main Jun 4, 2024
7 checks passed
@northwestwitch northwestwitch deleted the logging_outside_lifespan branch June 5, 2024 12:56
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.

3 participants