uvicorn
uvicorn copied to clipboard
feat(logging): add customizable access log format for Gunicorn style …
Summary
This PR adds support for Gunicorn-style customizable access log formatting to Uvicorn, addressing issue #527 .
Users can now specify custom access log formats using the --access-log-format CLI option or the access_log_format parameter in the Python API, supporting 20+ format atoms compatible with Gunicorn's specification.
Changes
-
New
GunicornAccessFormatterclass inuvicorn/logging.py- Supports 20+ Gunicorn format atoms (h, l, u, t, r, m, U, q, H, s, B, b, f, a, T, D, M, L, p)
- Basic Authentication username extraction
- Request header interpolation via
%({header}i)ssyntax - Response time tracking in multiple units
-
CLI option
--access-log-format- Example:
uvicorn app:app --access-log-format '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
- Example:
-
Python API parameter
access_log_format- Added to
Configclass andrun()function
- Added to
-
Protocol integration
- Modified
h11_impl.pyandhttptools_impl.pyto track response time and size - Automatic formatter detection (GunicornAccessFormatter vs AccessFormatter)
- Modified
Checklist
- [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- [x] I've updated the documentation accordingly.
@ZaneL1u
Can't wait to see this merged 💪 .
This would be nice for people running Gunicorn with Uvicorn workers.
Will it be in that way ? Or "just" applying Gunicorn logging style to Uvicorn ?