Skip to content

Conversation

@ZaneL1u
Copy link

@ZaneL1u ZaneL1u commented Nov 8, 2025

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 GunicornAccessFormatter class in uvicorn/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)s syntax
    • 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"'
  • Python API parameter access_log_format

    • Added to Config class and run() function
  • Protocol integration

    • Modified h11_impl.py and httptools_impl.py to track response time and size
    • Automatic formatter detection (GunicornAccessFormatter vs AccessFormatter)

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

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.

1 participant