Repository navigation
Please tell me how to fix this strange colouring scheme 'e:ba' and 'e:fe' turns out green #4230
Replies: 2 comments 3 replies
|
Try turning off auto highlighting: from rich.highlighter import NullHighlighter
console_handler = RichHandler(
markup=True,
show_time=False,
show_level=False,
show_path=False,
highlighter=NullHighlighter(),
) |
|
That's not your formatter, it's from rich.text import Text
from rich.highlighter import ReprHighlighter
t = Text("cable:balticcable status: False")
ReprHighlighter().highlight(t)
print([(t.plain[s.start:s.end], str(s.style)) for s in t.spans])
# [('e:ba', 'repr.ipv6'), ('False', 'repr.bool_false')]The most targeted fix is to blank just that style, so everything else keeps its colours: from rich.console import Console
from rich.theme import Theme
handler = RichHandler(console=Console(theme=Theme({"repr.ipv6": "none"})))(Real IPv6 addresses in your logs lose their colour too, which is probably fine.) If you'd rather Rich not guess at highlighting at all, turn it off on the handler: from rich.highlighter import NullHighlighter
from rich.logging import RichHandler
handler = RichHandler(highlighter=NullHighlighter())That also drops the other automatic styling (numbers, log.info("cable:balticcable status: False", extra={"highlighter": None})Checked with rich 15.0.0. |


That's not your formatter, it's
RichHandler's default highlighter. It runsReprHighlighterover every message, and one of its patterns is an IPv6 matcher,([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}inrich/highlighter.py. In "cable:balticcable" the bite:bais two hex groups separated by a colon, so it gets styled as an IPv6 address (repr.ipv6, bold bright green). Same fore:fein "cable:fennoskan". You can see it directly:T…