log-color-fix-3
This commit is contained in:
parent
695c9a97eb
commit
9a15cda218
|
@ -45,25 +45,11 @@ class MultilineColoredFormatter(colorlog.ColoredFormatter):
|
||||||
formatted_lines = [super().format(record)] # Format the first line with prefix
|
formatted_lines = [super().format(record)] # Format the first line with prefix
|
||||||
for line in lines[1:]:
|
for line in lines[1:]:
|
||||||
record.message = line # Set the message to the remaining lines one by one
|
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)
|
return '\n'.join(formatted_lines)
|
||||||
else:
|
else:
|
||||||
return super().format(record)
|
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
|
# Create a MultilineColoredFormatter object for colorized logging
|
||||||
formatter = MultilineColoredFormatter(fmt_string, **fmt_config)
|
formatter = MultilineColoredFormatter(fmt_string, **fmt_config)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user