Open vikramsubramanian opened 2 weeks ago
loguru/_colorizer.py:217-274 | The feed method in loguru/_colorizer.py needs to be updated to strip out the bold attribute if the LOGURU_NO_BOLD environment variable is set.
loguru/_defaults.py:1-73 | The loguru/_defaults.py file needs to be updated to define the new LOGURU_NO_BOLD environment variable and adjust color settings accordingly.
To address the feature request of suppressing bold text in log messages while preserving other text decorations like colors, follow these steps:
LOGURU_NO_BOLD
, to control the suppression of bold text.loguru/_defaults.py
to check for the new environment variable and adjust the color settings accordingly.loguru/_colorizer.py
to respect the new environment variable and strip out the bold attribute from the text decorations.Add the new environment variable in loguru/_defaults.py
:
LOGURU_NO_BOLD
and set default color settings.# loguru/_defaults.py
LOGURU_NO_BOLD = env("LOGURU_NO_BOLD", bool, False)
LOGURU_INFO_COLOR = env("LOGURU_INFO_COLOR", str, "<bold>")
LOGURU_WARNING_COLOR = env("LOGURU_WARNING_COLOR", str, "<yellow><bold>")
LOGURU_ERROR_COLOR = env("LOGURU_ERROR_COLOR", str, "<red><bold>")
if LOGURU_NO_BOLD:
LOGURU_INFO_COLOR = LOGURU_INFO_COLOR.replace("<bold>", "")
LOGURU_WARNING_COLOR = LOGURU_WARNING_COLOR.replace("<bold>", "")
LOGURU_ERROR_COLOR = LOGURU_ERROR_COLOR.replace("<bold>", "")
Update the feed
method in loguru/_colorizer.py
to strip out the bold attribute if the environment variable is set:
# loguru/_colorizer.py
def feed(self, text, *, raw=False):
if raw:
self._tokens.append((TokenType.TEXT, text))
return
position = 0
for match in self._regex_tag.finditer(text):
markup, tag = match.group(0), match.group(1)
if LOGURU_NO_BOLD and "bold" in tag:
tag = tag.replace("bold", "")
self._tokens.append((TokenType.TEXT, text[position : match.start()]))
position = match.end()
if markup[0] == "\\":
self._tokens.append((TokenType.TEXT, markup[1:]))
continue
if markup[1] == "/":
if self._tags and (tag == "" or tag == self._tags[-1]):
self._tags.pop()
self._color_tokens.pop()
self._tokens.append((TokenType.CLOSING, "\033[0m"))
self._tokens.extend(self._color_tokens)
continue
elif tag in self._tags:
raise ValueError('Closing tag "%s" violates nesting rules' % markup)
else:
raise ValueError('Closing tag "%s" has no corresponding opening tag' % markup)
if tag in {"lvl", "level"}:
token = (TokenType.LEVEL, None)
else:
ansi = self._get_ansicode(tag)
if ansi is None:
raise ValueError(
'Tag "%s" does not correspond to any known ansi directive, '
"make sure you did not misspelled it (or prepend '\\' to escape it)"
% markup
)
token = (TokenType.ANSI, ansi)
self._tags.append(tag)
self._color_tokens.append(token)
self._tokens.append(token)
self._tokens.append((TokenType.TEXT, text[position:]))
def done(self, *, strict=True):
if strict and self._tags:
faulty_tag = self._tags.pop(0)
raise ValueError('Opening tag "<%s>" has no corresponding closing tag' % faulty_tag)
return self._tokens
def current_color_tokens(self):
return list(self._color_tokens)
By following these steps, you will successfully suppress bold text in log messages while preserving other text decorations based on the new environment variable LOGURU_NO_BOLD
.
💡 To rerun Mayil, comment mayil-ai rerun
. Mayil will incorporate any new context added to the ticket. Include details in your rerun comment to guide Mayil!
I am quite happy with the default colours, however the bold text looks off.
Is there a way to preserve all decorations, but remove the bold? )