Skip to content

Commit ca89ff9

Browse files
committed
Put event fields on their own lines in line-rendering mode
1 parent e9dfaa7 commit ca89ff9

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

examples/basic.stdout

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
1:main│ ├┐basic::server host="localhost", port=8080
77
1:main│ │└┐basic::conn peer_addr="82.9.9.9", port=42381
88
1:main│ │ ├─ Xms DEBUG basic connected
9-
1:main│ │ ├─ Xms DEBUG basic message received, length=2
9+
1:main│ │ ├─┬─ Xms DEBUG basic message received
10+
1:main│ │ │ └─ length=2
1011
1:main│ │┌┘basic::conn peer_addr="82.9.9.9", port=42381
1112
1:main│ ├┘basic::server host="localhost", port=8080
1213
1:main│ ├┐basic::server host="localhost", port=8080
@@ -21,15 +22,19 @@
2122
1:main│ ├┘basic::server host="localhost", port=8080
2223
1:main│ ├┐basic::server host="localhost", port=8080
2324
1:main│ │└┐basic::conn peer_addr="82.9.9.9", port=42381
24-
1:main│ │ ├─ Xms WARN basic weak encryption requested, algo="xor"
25-
1:main│ │ ├─ Xms DEBUG basic response sent, length=8
25+
1:main│ │ ├─┬─ Xms WARN basic weak encryption requested
26+
1:main│ │ │ └─ algo="xor"
27+
1:main│ │ ├─┬─ Xms DEBUG basic response sent
28+
1:main│ │ │ └─ length=8
2629
1:main│ │ ├─ Xms DEBUG basic disconnected
2730
1:main│ │┌┘basic::conn peer_addr="82.9.9.9", port=42381
2831
1:main│ ├┘basic::server host="localhost", port=8080
2932
1:main│ ├┐basic::server host="localhost", port=8080
3033
1:main│ │└┐basic::conn peer_addr="8.8.8.8", port=18230
31-
1:main│ │ ├─ Xms DEBUG basic message received, length=5
32-
1:main│ │ ├─ Xms DEBUG basic response sent, length=8
34+
1:main│ │ ├─┬─ Xms DEBUG basic message received
35+
1:main│ │ │ └─ length=5
36+
1:main│ │ ├─┬─ Xms DEBUG basic response sent
37+
1:main│ │ │ └─ length=8
3338
1:main│ │ ├─ Xms DEBUG basic disconnected
3439
1:main│ │┌┘basic::conn peer_addr="8.8.8.8", port=18230
3540
1:main│ ├┘basic::server host="localhost", port=8080

examples/quiet.stdout

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
1:main│ ├─ Xms INFO quiet listening
55
1:main│ ├─┐quiet::conn peer_addr="82.9.9.9", port=42381
66
1:main│ │ ├─ Xms DEBUG quiet connected
7-
1:main│ │ ├─ Xms DEBUG quiet message received, length=2
7+
1:main│ │ ├─┬─ Xms DEBUG quiet message received
8+
1:main│ │ │ └─ length=2
89
1:main│ ├─┘
910
1:main│ ├─┐quiet::conn peer_addr="8.8.8.8", port=18230
1011
1:main│ │ ├─ Xms DEBUG quiet connected
@@ -13,13 +14,17 @@
1314
1:main│ │ ├─ Xms ERROR quiet hello
1415
1:main│ ├─┘
1516
1:main│ ├─┐quiet::conn peer_addr="82.9.9.9", port=42381
16-
1:main│ │ ├─ Xms WARN quiet weak encryption requested, algo="xor"
17-
1:main│ │ ├─ Xms DEBUG quiet response sent, length=8
17+
1:main│ │ ├─┬─ Xms WARN quiet weak encryption requested
18+
1:main│ │ │ └─ algo="xor"
19+
1:main│ │ ├─┬─ Xms DEBUG quiet response sent
20+
1:main│ │ │ └─ length=8
1821
1:main│ │ ├─ Xms DEBUG quiet disconnected
1922
1:main│ ├─┘
2023
1:main│ ├─┐quiet::conn peer_addr="8.8.8.8", port=18230
21-
1:main│ │ ├─ Xms DEBUG quiet message received, length=5
22-
1:main│ │ ├─ Xms DEBUG quiet response sent, length=8
24+
1:main│ │ ├─┬─ Xms DEBUG quiet message received
25+
1:main│ │ │ └─ length=5
26+
1:main│ │ ├─┬─ Xms DEBUG quiet response sent
27+
1:main│ │ │ └─ length=8
2328
1:main│ │ ├─ Xms DEBUG quiet disconnected
2429
1:main│ ├─┘
2530
1:main│ ├─ Xs WARN quiet internal error

src/format.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const LINE_HORIZ: &str = "─";
1313
pub(crate) const LINE_BRANCH: &str = "├";
1414
pub(crate) const LINE_CLOSE: &str = "┘";
1515
pub(crate) const LINE_OPEN: &str = "┐";
16+
pub(crate) const ARGS_BRANCH: &str = "┬";
1617

1718
#[derive(Copy, Clone)]
1819
pub(crate) enum SpanMode {
@@ -226,7 +227,7 @@ pub struct FmtEvent<'a> {
226227
impl<'a> Visit for FmtEvent<'a> {
227228
fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) {
228229
let buf = &mut self.bufs.current_buf;
229-
let comma = if self.comma { "," } else { "" };
230+
let comma = if self.comma { "\n" } else { "" };
230231
match field.name() {
231232
"message" => {
232233
write!(buf, "{} {:?}", comma, value).unwrap();
@@ -371,6 +372,12 @@ fn indent_block_with_lines(
371372
}
372373
SpanMode::Event => {
373374
buf.push_str(LINE_BRANCH);
375+
if lines.len() > 1 {
376+
for _ in 0..(indent_amount - 1) {
377+
buf.push_str(LINE_HORIZ);
378+
}
379+
buf.push_str(ARGS_BRANCH);
380+
}
374381

375382
// add `indent_amount - 1` horizontal lines before the span/event
376383
for _ in 0..(indent_amount - 1) {
@@ -392,8 +399,16 @@ fn indent_block_with_lines(
392399
}
393400

394401
// add all of the actual content, with each line preceded by the indent string
395-
for line in &lines[1..] {
402+
for (i, line) in lines[1..].iter().enumerate() {
396403
buf.push_str(&s);
404+
// Magic number `2` means "last entry" because we iterate from `1`
405+
// and then restart indexing at `0`.
406+
if i == lines.len() - 2 {
407+
buf.push_str("└");
408+
} else {
409+
buf.push_str(LINE_BRANCH);
410+
}
411+
buf.push_str(LINE_HORIZ);
397412
buf.push_str(line);
398413
buf.push('\n');
399414
}

0 commit comments

Comments
 (0)