Skip to content

Commit a3ad3cb

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

10 files changed

+115
-47
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 ├─ DEBUG basic connected
9-
1:main ├─ DEBUG basic message received, length=2
9+
1:main ├─┬─ 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 ├─ WARN basic weak encryption requested, algo="xor"
25-
1:main ├─ DEBUG basic response sent, length=8
25+
1:main ├─┬─ WARN basic weak encryption requested
26+
1:main │ └─ algo="xor"
27+
1:main ├─┬─ DEBUG basic response sent
28+
1:main │ └─ length=8
2629
1:main ├─ 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 ├─ DEBUG basic message received, length=5
32-
1:main ├─ DEBUG basic response sent, length=8
34+
1:main ├─┬─ DEBUG basic message received
35+
1:main │ └─ length=5
36+
1:main ├─┬─ DEBUG basic response sent
37+
1:main │ └─ length=8
3338
1:main ├─ 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/basic_non_verbose.stdout

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

examples/basic_verbose_entry.stdout

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
1:main └┐basic_verbose_entry::server host="localhost", port=8080
77
1:main └┐basic_verbose_entry::conn peer_addr="82.9.9.9", port=42381
88
1:main ├─ DEBUG basic_verbose_entry connected
9-
1:main ├─ DEBUG basic_verbose_entry message received, length=2
9+
1:main ├─┬─ DEBUG basic_verbose_entry message received
10+
1:main │ └─ length=2
1011
1:main ┌─┘
1112
1:main └┐basic_verbose_entry::server host="localhost", port=8080
1213
1:main └┐basic_verbose_entry::conn peer_addr="8.8.8.8", port=18230
@@ -18,14 +19,18 @@
1819
1:main ┌─┘
1920
1:main └┐basic_verbose_entry::server host="localhost", port=8080
2021
1:main └┐basic_verbose_entry::conn peer_addr="82.9.9.9", port=42381
21-
1:main ├─ WARN basic_verbose_entry weak encryption requested, algo="xor"
22-
1:main ├─ DEBUG basic_verbose_entry response sent, length=8
22+
1:main ├─┬─ WARN basic_verbose_entry weak encryption requested
23+
1:main │ └─ algo="xor"
24+
1:main ├─┬─ DEBUG basic_verbose_entry response sent
25+
1:main │ └─ length=8
2326
1:main ├─ DEBUG basic_verbose_entry disconnected
2427
1:main ┌─┘
2528
1:main └┐basic_verbose_entry::server host="localhost", port=8080
2629
1:main └┐basic_verbose_entry::conn peer_addr="8.8.8.8", port=18230
27-
1:main ├─ DEBUG basic_verbose_entry message received, length=5
28-
1:main ├─ DEBUG basic_verbose_entry response sent, length=8
30+
1:main ├─┬─ DEBUG basic_verbose_entry message received
31+
1:main │ └─ length=5
32+
1:main ├─┬─ DEBUG basic_verbose_entry response sent
33+
1:main │ └─ length=8
2934
1:main ├─ DEBUG basic_verbose_entry disconnected
3035
1:main ┌─┘
3136
1:main ├─ WARN basic_verbose_entry internal error

examples/basic_verbose_exit.stdout

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
1:main ├─ INFO basic_verbose_exit listening
55
1:main └─┐basic_verbose_exit::conn peer_addr="82.9.9.9", port=42381
66
1:main ├─ DEBUG basic_verbose_exit connected
7-
1:main ├─ DEBUG basic_verbose_exit message received, length=2
7+
1:main ├─┬─ DEBUG basic_verbose_exit message received
8+
1:main │ └─ length=2
89
1:main ┌┘basic_verbose_exit::conn peer_addr="82.9.9.9", port=42381
910
1:main ┌┘basic_verbose_exit::server host="localhost", port=8080
1011
1:main └─┐basic_verbose_exit::conn peer_addr="8.8.8.8", port=18230
@@ -16,14 +17,18 @@
1617
1:main ┌┘basic_verbose_exit::foomp 42 <- format string, normal_var=43
1718
1:main ┌┘basic_verbose_exit::server host="localhost", port=8080
1819
1:main └─┐basic_verbose_exit::conn peer_addr="82.9.9.9", port=42381
19-
1:main ├─ WARN basic_verbose_exit weak encryption requested, algo="xor"
20-
1:main ├─ DEBUG basic_verbose_exit response sent, length=8
20+
1:main ├─┬─ WARN basic_verbose_exit weak encryption requested
21+
1:main │ └─ algo="xor"
22+
1:main ├─┬─ DEBUG basic_verbose_exit response sent
23+
1:main │ └─ length=8
2124
1:main ├─ DEBUG basic_verbose_exit disconnected
2225
1:main ┌┘basic_verbose_exit::conn peer_addr="82.9.9.9", port=42381
2326
1:main ┌┘basic_verbose_exit::server host="localhost", port=8080
2427
1:main └─┐basic_verbose_exit::conn peer_addr="8.8.8.8", port=18230
25-
1:main ├─ DEBUG basic_verbose_exit message received, length=5
26-
1:main ├─ DEBUG basic_verbose_exit response sent, length=8
28+
1:main ├─┬─ DEBUG basic_verbose_exit message received
29+
1:main │ └─ length=5
30+
1:main ├─┬─ DEBUG basic_verbose_exit response sent
31+
1:main │ └─ length=8
2732
1:main ├─ DEBUG basic_verbose_exit disconnected
2833
1:main ┌┘basic_verbose_exit::conn peer_addr="8.8.8.8", port=18230
2934
1:main ┌┘basic_verbose_exit::server host="localhost", port=8080

examples/concurrent.stdout

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
1:main ├─── DEBUG concurrent starting countdowns
66
1:main └───┐concurrent::countdowns
77
1:main └───┐concurrent::countdown_a
8-
1:main ├─── DEBUG concurrent polling countdown, label="a", count=3
8+
1:main ├───┬─── DEBUG concurrent polling countdown
9+
1:main │ ├─ label="a"
10+
1:main │ └─ count=3
911
1:main └───┐concurrent::countdown_b
10-
1:main ├─── DEBUG concurrent polling countdown, label="b", count=5
11-
1:main ├─── DEBUG concurrent polling countdown, label="b", count=4
12+
1:main ├───┬─── DEBUG concurrent polling countdown
13+
1:main │ ├─ label="b"
14+
1:main │ └─ count=5
15+
1:main ├───┬─── DEBUG concurrent polling countdown
16+
1:main │ ├─ label="b"
17+
1:main │ └─ count=4
1218
1:main └───┐concurrent::countdown_a
13-
1:main ├─── DEBUG concurrent polling countdown, label="a", count=2
19+
1:main ├───┬─── DEBUG concurrent polling countdown
20+
1:main │ ├─ label="a"
21+
1:main │ └─ count=2
1422
1:main └───┐concurrent::conn peer_addr="82.9.9.9", port=42381
1523
1:main ├─── WARN concurrent peer1 warning
1624
1:main └───┐concurrent::countdowns

examples/concurrent_verbose.stdout

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@
66
1:main └─┐concurrent_verbose::server host="localhost", port=8080
77
1:main └─┐concurrent_verbose::countdowns
88
1:main └───┐concurrent_verbose::countdown_a
9-
1:main ├─── DEBUG concurrent_verbose polling countdown, label="a", count=3
9+
1:main ├───┬─── DEBUG concurrent_verbose polling countdown
10+
1:main │ ├─ label="a"
11+
1:main │ └─ count=3
1012
1:main └─┐concurrent_verbose::countdowns
1113
1:main └─┐concurrent_verbose::countdown_b
12-
1:main ├─── DEBUG concurrent_verbose polling countdown, label="b", count=5
13-
1:main ├─── DEBUG concurrent_verbose polling countdown, label="b", count=4
14+
1:main ├───┬─── DEBUG concurrent_verbose polling countdown
15+
1:main │ ├─ label="b"
16+
1:main │ └─ count=5
17+
1:main ├───┬─── DEBUG concurrent_verbose polling countdown
18+
1:main │ ├─ label="b"
19+
1:main │ └─ count=4
1420
1:main └─┐concurrent_verbose::countdowns
1521
1:main └─┐concurrent_verbose::countdown_a
16-
1:main ├─── DEBUG concurrent_verbose polling countdown, label="a", count=2
22+
1:main ├───┬─── DEBUG concurrent_verbose polling countdown
23+
1:main │ ├─ label="a"
24+
1:main │ └─ count=2
1725
1:main └─┐concurrent_verbose::server host="localhost", port=8080
1826
1:main └─┐concurrent_verbose::conn peer_addr="82.9.9.9", port=42381
1927
1:main ├─── WARN concurrent_verbose peer1 warning

examples/deferred.stdout

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
1:main └┐pre_open: deferred::server host="localhost", port=8080
88
1:main └┐open(v): deferred::connections
99
1:main └─┐open: deferred::conn peer_addr="82.9.9.9", port=42381
10-
1:main ├─ DEBUG deferred connected, peer="peer1"
11-
1:main ├─ DEBUG deferred message received, length=2
10+
1:main ├─┬─ DEBUG deferred connected
11+
1:main │ └─ peer="peer1"
12+
1:main ├─┬─ DEBUG deferred message received
13+
1:main │ └─ length=2
1214
1:main ┌┘close(v): deferred::conn peer_addr="82.9.9.9", port=42381
1315
1:main ┌┘post_close: deferred::connections
1416
1:main └┐pre_open: deferred::connections
1517
1:main └┐open(v): deferred::conn peer_addr="8.8.8.8", port=18230
16-
1:main ├─ DEBUG deferred connected, peer="peer3"
18+
1:main ├─┬─ DEBUG deferred connected
19+
1:main │ └─ peer="peer3"
1720
1:main ┌┘close(v): deferred::conn peer_addr="8.8.8.8", port=18230
1821
1:main ┌┘post_close: deferred::connections
1922
1:main └┐pre_open: deferred::connections
@@ -23,15 +26,19 @@
2326
1:main ┌┘post_close: deferred::connections
2427
1:main └┐pre_open: deferred::connections
2528
1:main └┐open(v): deferred::conn peer_addr="82.9.9.9", port=42381
26-
1:main ├─ WARN deferred weak encryption requested, algo="xor"
27-
1:main ├─ DEBUG deferred response sent, length=8
29+
1:main ├─┬─ WARN deferred weak encryption requested
30+
1:main │ └─ algo="xor"
31+
1:main ├─┬─ DEBUG deferred response sent
32+
1:main │ └─ length=8
2833
1:main ├─ DEBUG deferred disconnected
2934
1:main ┌┘close(v): deferred::conn peer_addr="82.9.9.9", port=42381
3035
1:main ┌┘post_close: deferred::connections
3136
1:main └┐pre_open: deferred::connections
3237
1:main └┐open(v): deferred::conn peer_addr="8.8.8.8", port=18230
33-
1:main ├─ DEBUG deferred message received, length=5
34-
1:main ├─ DEBUG deferred response sent, length=8
38+
1:main ├─┬─ DEBUG deferred message received
39+
1:main │ └─ length=5
40+
1:main ├─┬─ DEBUG deferred response sent
41+
1:main │ └─ length=8
3542
1:main ├─ DEBUG deferred disconnected
3643
1:main ┌┘close(v): deferred::conn peer_addr="8.8.8.8", port=18230
3744
1:main ┌┘post_close: deferred::connections

examples/no-indent.stdout

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44
1:main INFO no_indent listening
55
1:main no_indent::conn peer_addr="82.9.9.9", port=42381
66
1:main DEBUG no_indent connected
7-
1:main DEBUG no_indent message received, length=2
7+
1:main DEBUG no_indent message received
8+
1:main length=2
89
1:main no_indent::conn peer_addr="8.8.8.8", port=18230
910
1:main DEBUG no_indent connected
1011
1:main no_indent::foomp 42 <- format string, normal_var=43
1112
1:main ERROR no_indent hello
1213
1:main no_indent::conn peer_addr="82.9.9.9", port=42381
13-
1:main WARN no_indent weak encryption requested, algo="xor"
14-
1:main DEBUG no_indent response sent, length=8
14+
1:main WARN no_indent weak encryption requested
15+
1:main algo="xor"
16+
1:main DEBUG no_indent response sent
17+
1:main length=8
1518
1:main DEBUG no_indent disconnected
1619
1:main no_indent::conn peer_addr="8.8.8.8", port=18230
17-
1:main DEBUG no_indent message received, length=5
18-
1:main DEBUG no_indent response sent, length=8
20+
1:main DEBUG no_indent message received
21+
1:main length=5
22+
1:main DEBUG no_indent response sent
23+
1:main length=8
1924
1:main DEBUG no_indent disconnected
2025
1:main WARN no_indent internal error
2126
1:main INFO no_indent exit

examples/quiet.stdout

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

src/format.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(crate) const LINE_BRANCH: &str = "├";
1414
pub(crate) const LINE_CLOSE: &str = "┘";
1515
pub(crate) const LINE_CLOSE2: char = '┌';
1616
pub(crate) const LINE_OPEN: &str = "┐";
17+
pub(crate) const ARGS_BRANCH: &str = "┬";
1718
pub(crate) const LINE_OPEN2: char = '└';
1819

1920
#[derive(Debug, Copy, Clone)]
@@ -277,7 +278,7 @@ pub struct FmtEvent<'a> {
277278
impl<'a> Visit for FmtEvent<'a> {
278279
fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) {
279280
let buf = &mut self.bufs.current_buf;
280-
let comma = if self.comma { "," } else { "" };
281+
let comma = if self.comma { "\n" } else { "" };
281282
match field.name() {
282283
"message" => {
283284
write!(buf, "{} {:?}", comma, value).unwrap();
@@ -436,6 +437,12 @@ fn indent_block_with_lines(
436437
}
437438
SpanMode::Event => {
438439
buf.push_str(LINE_BRANCH);
440+
if lines.len() > 1 {
441+
for _ in 0..(indent_amount - 1) {
442+
buf.push_str(LINE_HORIZ);
443+
}
444+
buf.push_str(ARGS_BRANCH);
445+
}
439446

440447
// add `indent_amount - 1` horizontal lines before the span/event
441448
for _ in 0..(indent_amount - 1) {
@@ -457,8 +464,16 @@ fn indent_block_with_lines(
457464
}
458465

459466
// add all of the actual content, with each line preceded by the indent string
460-
for line in &lines[1..] {
467+
for (i, line) in lines[1..].iter().enumerate() {
461468
buf.push_str(&s);
469+
// Magic number `2` means "last entry" because we iterate from `1`
470+
// and then restart indexing at `0`.
471+
if i == lines.len() - 2 {
472+
buf.push('└');
473+
} else {
474+
buf.push_str(LINE_BRANCH);
475+
}
476+
buf.push_str(LINE_HORIZ);
462477
buf.push_str(line);
463478
buf.push('\n');
464479
}

0 commit comments

Comments
 (0)