Skip to content

Commit c53512c

Browse files
committed
hotfix(logging.py): fix messages being truncated on small terminals
1 parent 2a7a480 commit c53512c

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

tux/utils/logging.py

+7-27
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def emit(self, record: LogRecord) -> None:
9191
record : LogRecord
9292
The log record to emit.
9393
"""
94-
9594
try:
9695
# Get the formatted message
9796
message = self.format(record)
@@ -120,42 +119,23 @@ def emit(self, record: LogRecord) -> None:
120119
"success": "[bold green]█[/]", # Green block for success
121120
"trace": "[dim]█[/]", # Dim block for trace
122121
}
123-
124122
symbol = level_symbols.get(level_name, "[bright_black]█[/]") # Gray block for default
125123
level_str = f"{record.levelname:<7}" # Reduced padding by 1
126124

127-
# Format source info
125+
# Format source info and display it as part of the log prefix (before the actual message)
128126
source_info = (
129127
f"[dim]{record.funcName}[bright_black] @ [/bright_black]{record.filename}:{record.lineno}[/dim]"
130128
)
131129

132-
# Get the main log message part
133-
log_prefix = f"{symbol} [log.time]{log_time_str}[/][log.bracket][[/][logging.level.{level_name}]{level_str}[/][log.bracket]][/] "
134-
135-
# Calculate available width for the message
136-
terminal_width = self.console.width or 120
137-
source_info_length = (
138-
len(record.funcName) + len(record.filename) + len(str(record.lineno)) + 2
139-
) # +2 for @ and :
140-
available_width = (
141-
terminal_width - len(Text.from_markup(log_prefix).plain) - source_info_length - 2
142-
) # -2 for spacing
143-
144-
# Truncate message if needed and add ellipsis
145-
if len(message) > available_width - 3: # -3 for ...
146-
message = f"{message[: available_width - 3]}..."
130+
log_prefix = (
131+
f"{symbol} [log.time]{log_time_str}[/]"
132+
f"[log.bracket][[/][logging.level.{level_name}]{level_str}[/][log.bracket]][/] "
133+
f"{source_info} "
134+
)
147135

148-
# Right align the source info
136+
# Print the complete log line with the source info preceding the actual log message.
149137
self.console.print(
150138
f"{log_prefix}{message}",
151-
end="",
152-
markup=True,
153-
highlight=False,
154-
)
155-
self.console.print(
156-
source_info,
157-
justify="right",
158-
width=terminal_width - len(Text.from_markup(f"{log_prefix}{message}").plain),
159139
markup=True,
160140
highlight=False,
161141
)

0 commit comments

Comments
 (0)