-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -56,15 +65,6 @@ def configure_static(app): | |||
|
|||
|
|||
async def startup_db(): | |||
# Configure logging |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, 👍
src/chanjo2/main.py
Outdated
console_formatter = uvicorn.logging.ColourizedFormatter( | ||
"{levelprefix} {asctime} : {message}", style="{", use_colors=True | ||
) | ||
if LOG.handlers: | ||
LOG.handlers[0].setFormatter(console_formatter) | ||
else: | ||
logging.basicConfig() | ||
|
||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, good suggestion! 👍🏻
src/chanjo2/main.py
Outdated
@@ -23,6 +23,15 @@ | |||
(overview.router, "overview"), | |||
] | |||
|
|||
# Configure logging | |||
console_formatter = uvicorn.logging.ColourizedFormatter( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Quality Gate passedIssues Measures |
Description
It's not a fix for #308, but setting up logging should be outside the function for the database setup
How to test
Review
This version is a