Skip to content

Commit 0d16926

Browse files
committed
Escape < in logging extras so they aren't treated as colour tags
1 parent db37f8b commit 0d16926

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/fastcs/logging/_logging.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
from enum import StrEnum
44
from logging import LogRecord
5-
from typing import TYPE_CHECKING
5+
from typing import TYPE_CHECKING, Any
66

77
from prompt_toolkit.patch_stdout import StdoutProxy
88
from pygelf import GelfUdpHandler
@@ -79,7 +79,8 @@ def format_record(record) -> str:
7979
sep = "<white>,</white> "
8080
if "extra" in record:
8181
extras = [
82-
format_key_value(k, v)
82+
# Escape `<` so Loguru doesn't parse them as format tags
83+
format_key_value(k, f"{v}".replace("<", r"\<"))
8384
for k, v in record["extra"].items()
8485
if not k.startswith("_")
8586
]
@@ -99,7 +100,7 @@ def format_record(record) -> str:
99100
"""
100101

101102

102-
def format_key_value(k, v):
103+
def format_key_value(k: Any, v: Any) -> str:
103104
return f"<cyan>{k}</cyan><white>=</white><magenta>{v}</magenta>"
104105

105106

0 commit comments

Comments
 (0)