@@ -91,7 +91,6 @@ def emit(self, record: LogRecord) -> None:
91
91
record : LogRecord
92
92
The log record to emit.
93
93
"""
94
-
95
94
try :
96
95
# Get the formatted message
97
96
message = self .format (record )
@@ -120,42 +119,23 @@ def emit(self, record: LogRecord) -> None:
120
119
"success" : "[bold green]█[/]" , # Green block for success
121
120
"trace" : "[dim]█[/]" , # Dim block for trace
122
121
}
123
-
124
122
symbol = level_symbols .get (level_name , "[bright_black]█[/]" ) # Gray block for default
125
123
level_str = f"{ record .levelname :<7} " # Reduced padding by 1
126
124
127
- # Format source info
125
+ # Format source info and display it as part of the log prefix (before the actual message)
128
126
source_info = (
129
127
f"[dim]{ record .funcName } [bright_black] @ [/bright_black]{ record .filename } :{ record .lineno } [/dim]"
130
128
)
131
129
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
+ )
147
135
148
- # Right align the source info
136
+ # Print the complete log line with the source info preceding the actual log message.
149
137
self .console .print (
150
138
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 ),
159
139
markup = True ,
160
140
highlight = False ,
161
141
)
0 commit comments