Skip to content

Commit

Permalink
Logging: Escape rich markup sequences
Browse files Browse the repository at this point in the history
Rich markup sequences inside the log string were causing issues
with printing. Fix this by using their escape function.

Signed-off-by: kingbri <[email protected]>
  • Loading branch information
kingbri1 committed Mar 11, 2024
1 parent 4cc0b59 commit ba3da6d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from loguru import logger
from rich.console import Console
from rich.markup import escape
from rich.progress import (
Progress,
TextColumn,
Expand Down Expand Up @@ -32,7 +33,7 @@ def get_loading_progress_bar():
)


def _log_formatter(record: dict) -> str:
def _log_formatter(record: dict):
"""Log message formatter."""

color_map = {
Expand All @@ -54,6 +55,9 @@ def _log_formatter(record: dict) -> str:

# Replace once loguru allows for turning off str.format
message = message.replace("{", "{{").replace("}", "}}").replace("<", "\<")

# Escape markup tags from Rich
message = escape(message)
lines = message.splitlines()

fmt = ""
Expand Down

0 comments on commit ba3da6d

Please sign in to comment.