-
Notifications
You must be signed in to change notification settings - Fork 429
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
feat: JSON logging for Gunicorn #3672
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Overall looks good, just some minor comments.
"thread_name": record.threadName, | ||
} | ||
|
||
def format(self, record: logging.LogRecord) -> str: |
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.
The docstring of this function is now out of date.
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.
Thanks, removed!
class GunicornJsonLogger(GunicornLogger): | ||
def setup(self, cfg: Config) -> None: | ||
super().setup(cfg) | ||
if settings.LOG_FORMAT == "json": |
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.
If it's not set to JSON then the logger won't really be a JSON logger, right? It's weird to let it operate as a normal logger with the name of the class GunicornJsonLogger
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.
Renamed to GunicornJsonCapableLogger
.
- `ACCESS_LOG_LOCATION`: The location to store web logs generated by Gunicorn if running as a Docker container. If not | ||
set, no logs will be stored. If set to `-` the logs will be sent to `stdout`. |
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.
If not set, no logs will be stored.
I think if no logs will be stored then stdout
will actually be used, which is what we should say here, no?
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.
Thanks! Updated the docs.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3672 +/- ##
==========================================
- Coverage 95.86% 95.84% -0.02%
==========================================
Files 1099 1099
Lines 34422 34428 +6
==========================================
- Hits 33000 32999 -1
- Misses 1422 1429 +7 ☔ View full report in Codecov by Sentry. |
This reverts commit 3ce1754.
Thanks for submitting a PR! Please check the boxes below:
pre-commit
to check lintingdocs/
if required so people know about the feature!Changes
This PR does the following:
gunicorn.conf.py
file. This allows users to override Gunicorn settings using theGUNICORN_CMD_ARGS
environment variable.GunicornAccessLogJsonFormatter
andGunicornJsonLogger
to make Gunicorn respect theLOG_FORMAT
setting.ACCESS_LOG_FORMAT
environment variable.make serve
now configures Gunicorn withgunicorn.conf.py
.Closes #3637.
How did you test this code?
Ran
make serve
locally withLOG_FORMAT
,ACCESS_LOG_FORMAT
andACCESS_LOG_LOCATION
set to various values.