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

Logging improvements #2931

Merged
merged 44 commits into from
Apr 7, 2024
Merged

Logging improvements #2931

merged 44 commits into from
Apr 7, 2024

Conversation

ahopkins
Copy link
Member

@ahopkins ahopkins commented Mar 31, 2024

This replaces the nice work that @Tronic did on #2852 to include debug and prod style logging, as well as a legacy formatter to allow for backwards compat logging for some period of time.

Debug logging

image

Prod logging (w/ access logs explicitly on)

image


As you can see the main difference is just in the usage of the timestamp. We skip it in Debug (except for access logs).

Tronic and others added 23 commits November 16, 2023 10:13
… on server shutdownm with incoming connections;
… Access log doesn't need level printed either.
@ahopkins ahopkins requested a review from a team as a code owner March 31, 2024 14:17
@ahopkins ahopkins requested a review from a team as a code owner April 1, 2024 05:44
Copy link

codecov bot commented Apr 1, 2024

Codecov Report

Attention: Patch coverage is 74.10359% with 65 lines in your changes are missing coverage. Please review.

Project coverage is 87.626%. Comparing base (1a70930) to head (9e19653).
Report is 1 commits behind head on main.

❗ Current head 9e19653 differs from pull request most recent head 818a67a. Consider uploading reports for the commit 818a67a to get more accurate results

Files Patch % Lines
sanic/server/protocols/websocket_protocol.py 28.571% 28 Missing and 2 partials ⚠️
sanic/logging/formatter.py 88.095% 6 Missing and 4 partials ⚠️
sanic/server/websockets/impl.py 33.333% 10 Missing ⚠️
sanic/server/protocols/http_protocol.py 25.000% 9 Missing ⚠️
sanic/logging/setup.py 84.210% 2 Missing and 1 partial ⚠️
sanic/worker/manager.py 85.714% 1 Missing and 1 partial ⚠️
sanic/http/http1.py 83.333% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##              main     #2931       +/-   ##
=============================================
- Coverage   87.985%   87.626%   -0.360%     
=============================================
  Files           94       101        +7     
  Lines         7408      7597      +189     
  Branches      1307      1328       +21     
=============================================
+ Hits          6518      6657      +139     
- Misses         599       644       +45     
- Partials       291       296        +5     

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

@prryplatypus
Copy link
Member

What's the reason for removing the timestamp? I personally find it useful while developing - helps spotting slow bits of code and correlating events between systems/apps (for example if you have a webserver and a background worker).

@ahopkins
Copy link
Member Author

ahopkins commented Apr 1, 2024

@prryplatypus Muddies up the logs more than necessary if not needed. If it is needed, it is not so difficult to get the timestamps:

from sanic.log import LOGGING_CONFIG_DEFAULTS

LOGGING_CONFIG_DEFAULTS['formatters']['generic']['class'] = 'sanic.logging.formatter.ProdFormatter'

Perhaps we could make it all even simpler with config values on the Sanic app. Something like:

app.config.LOG_FORMATTER = "sanic.logging.formatter.ProdFormatter"

FWIW, uvicorn doesn't even give you timestamps on access logs.

image

@ahopkins
Copy link
Member Author

ahopkins commented Apr 1, 2024

image

FWIW, even with the time in dev (no date, just time) we still pick up a lot of real estate and cleanliness.

@prryplatypus
Copy link
Member

I'd be happy with just time 👀

@ahopkins ahopkins merged commit bc1a3eb into main Apr 7, 2024
25 checks passed
@ahopkins ahopkins deleted the logging-improvements branch April 7, 2024 07:21
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