Skip to content

Commit

Permalink
fix: remove ANSI escape sequences before putting log message in queue
Browse files Browse the repository at this point in the history
  • Loading branch information
qx6ghqkz committed Jan 11, 2025
1 parent d696ac1 commit 4df03af
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions gallery_dl_server/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ def format(self, record):
record.levelname = record.levelname.lower()

message = super().format(record)
return self.remove_ansi_escape_sequences(message)
return remove_ansi_escape_sequences(message)

def remove_ansi_escape_sequences(self, text):
ansi_escape_pattern = re.compile(r"\x1B\[[0-?9;]*[mGKH]")
return ansi_escape_pattern.sub("", text)

def remove_ansi_escape_sequences(text):
"""Remove ANSI escape sequences from the given text."""
ansi_escape_pattern = re.compile(r"\x1B\[[0-?9;]*[mGKH]")
return ansi_escape_pattern.sub("", text)


def get_logger(name):
Expand Down Expand Up @@ -122,7 +124,7 @@ def __init__(self, queue):
self.queue = queue

def emit(self, record):
record.msg = self.format(record)
record.msg = remove_ansi_escape_sequences(self.format(record))
record_dict = record_to_dict(record)

self.queue.put(record_dict)
Expand Down

0 comments on commit 4df03af

Please sign in to comment.