Skip to content

Commit f884eab

Browse files
lovasoaclaude
andcommitted
preserve multi-line error formatting in terminal log output
When stderr is a terminal and the log message contains newlines (e.g. SQL syntax errors with source highlighting and arrows), print the metadata on the first line and the message below with its original formatting. Machine output (non-terminal) remains single-line logfmt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1309725 commit f884eab

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/telemetry.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,14 @@ mod logfmt {
244244
let _ = write!(buf, " target={target}");
245245
}
246246

247-
// 4. msg
248-
if let Some(msg) = event_fields.get("message") {
249-
write_logfmt_value(&mut buf, "msg", msg);
247+
// 4. msg — for terminal, preserve multi-line formatting (e.g. SQL
248+
// error highlighting with arrows); for machine output, flatten.
249+
let msg = event_fields.get("message");
250+
let multiline_msg = colors && msg.is_some_and(|m| m.contains('\n'));
251+
if !multiline_msg {
252+
if let Some(msg) = msg {
253+
write_logfmt_value(&mut buf, "msg", msg);
254+
}
250255
}
251256

252257
// 5. Selected span fields in order
@@ -289,6 +294,15 @@ mod logfmt {
289294

290295
buf.push('\n');
291296

297+
// For multi-line messages on a terminal, print the message below
298+
// the metadata line with its original formatting preserved.
299+
if multiline_msg {
300+
if let Some(msg) = msg {
301+
buf.push_str(msg);
302+
buf.push('\n');
303+
}
304+
}
305+
292306
// Write atomically to stderr
293307
let _ = io::Write::write_all(&mut io::stderr().lock(), buf.as_bytes());
294308
}

0 commit comments

Comments
 (0)