gh-146292: Add colour to http.server logs#146293
Open
hugovk wants to merge 2 commits intopython:mainfrom
Open
Conversation
Co-authored-by: Brian Schubert <[email protected]>
picnixz
reviewed
Mar 22, 2026
| import threading | ||
| from unittest import mock | ||
| from io import BytesIO, StringIO | ||
| lazy from _colorize import get_theme |
Member
There was a problem hiding this comment.
I do not think lazy imports are necessary.
| elif code_int >= 400: | ||
| code_color = t.status_error | ||
| else: | ||
| code_color = t.status_ok |
Member
There was a problem hiding this comment.
Strictly speaking I would prefer that we also distinguish 300 and 100 codes as the former are redirections and the latter are informational.
Informational are less important in some sense and thus it makes sense to have another color (i would suggest white for informational and something else for 3xx, like lightblue).
I would have expected 2xx to be green though
| serving: str = ANSIColors.GREEN | ||
| size: str = ANSIColors.GREY | ||
| status_ok: str = ANSIColors.BLUE | ||
| status_error: str = ANSIColors.YELLOW |
Member
There was a problem hiding this comment.
Can you name this client error instead of just error please?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Taking inspiration from the
make devlogs for the new blog (https://github.com/python/python-insider-blog):Let's add colour to the
http.serverlog output:As usual, this respects the environment variables to control colour and the output stream's capabilities.
http.serverlogs #146292📚 Documentation preview 📚: https://cpython-previews--146293.org.readthedocs.build/