log-color-fix-3

This commit is contained in:
Untone 2024-03-12 18:24:44 +03:00
parent 695c9a97eb
commit 9a15cda218

View File

@ -45,25 +45,11 @@ class MultilineColoredFormatter(colorlog.ColoredFormatter):
formatted_lines = [super().format(record)] # Format the first line with prefix
for line in lines[1:]:
record.message = line # Set the message to the remaining lines one by one
formatted_lines.append(self.format_secondary_line(record)) # Format without prefix
formatted_lines.append(record.getMessage())
return '\n'.join(formatted_lines)
else:
return super().format(record)
def format_secondary_line(self, record):
msg = record.getMessage()
log_color = self.log_colors.get(record.levelname, 'reset')
formatted_msg = []
# Since there are no secondary log colors in the subsequent lines,
# we apply the log_color to each part of the message.
for part in msg.split(' '):
formatted_msg.append(f"{log_color}{part}{self.reset}")
return ' '.join(formatted_msg)
# Create a MultilineColoredFormatter object for colorized logging
formatter = MultilineColoredFormatter(fmt_string, **fmt_config)