log-color-fix

This commit is contained in:
Untone 2024-03-12 18:17:28 +03:00
parent b6691b1b7b
commit 695c9a97eb

View File

@ -51,19 +51,20 @@ class MultilineColoredFormatter(colorlog.ColoredFormatter):
return super().format(record) return super().format(record)
def format_secondary_line(self, record): def format_secondary_line(self, record):
msg = self.formatMessage(record) msg = record.getMessage()
log_color = self.log_colors.get(record.levelname, 'reset') log_color = self.log_colors.get(record.levelname, 'reset')
secondary_colors = self.secondary_log_colors.get(record.name, {})
formatted_msg = [] 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(' '): for part in msg.split(' '):
color = secondary_colors.get(part.split('=')[0], log_color) formatted_msg.append(f"{log_color}{part}{self.reset}")
formatted_msg.append(f"{color}{part}{self.reset}")
return ' '.join(formatted_msg) return ' '.join(formatted_msg)
# Create a MultilineColoredFormatter object for colorized logging # Create a MultilineColoredFormatter object for colorized logging
formatter = MultilineColoredFormatter(fmt_string, **fmt_config) formatter = MultilineColoredFormatter(fmt_string, **fmt_config)