logger-fix
This commit is contained in:
parent
4667168636
commit
b6691b1b7b
|
@ -32,19 +32,36 @@ fmt_config = {
|
||||||
|
|
||||||
|
|
||||||
class MultilineColoredFormatter(colorlog.ColoredFormatter):
|
class MultilineColoredFormatter(colorlog.ColoredFormatter):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.log_colors = kwargs.pop('log_colors', {})
|
||||||
|
self.secondary_log_colors = kwargs.pop('secondary_log_colors', {})
|
||||||
|
|
||||||
def format(self, record):
|
def format(self, record):
|
||||||
message = record.getMessage()
|
message = record.getMessage()
|
||||||
if '\n' in message:
|
if '\n' in message:
|
||||||
lines = message.split('\n')
|
lines = message.split('\n')
|
||||||
record.message = lines[0] # Keep only the first line in the record
|
record.message = lines[0] # Keep only the first line in the record
|
||||||
formatted_lines = [super().format(record)] # Format the first line
|
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(super().format(record)) # Format without prefix
|
formatted_lines.append(self.format_secondary_line(record)) # Format without prefix
|
||||||
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 = self.formatMessage(record)
|
||||||
|
log_color = self.log_colors.get(record.levelname, 'reset')
|
||||||
|
secondary_colors = self.secondary_log_colors.get(record.name, {})
|
||||||
|
formatted_msg = []
|
||||||
|
|
||||||
|
for part in msg.split(' '):
|
||||||
|
color = secondary_colors.get(part.split('=')[0], log_color)
|
||||||
|
formatted_msg.append(f"{color}{part}{self.reset}")
|
||||||
|
|
||||||
|
return ' '.join(formatted_msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Create a MultilineColoredFormatter object for colorized logging
|
# Create a MultilineColoredFormatter object for colorized logging
|
||||||
|
|
Loading…
Reference in New Issue
Block a user