Skip to content

Commit

Permalink
Put span fields on their own lines in line rendering mode
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed May 23, 2023
1 parent 73e521d commit bd7a397
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 42 deletions.
66 changes: 44 additions & 22 deletions examples/basic.stdout
Original file line number Diff line number Diff line change
@@ -1,46 +1,68 @@
1:main┐basic::hierarchical-example version=0.1
1:main├┐basic::hierarchical-example version=0.1
1:main│└┐basic::server host="localhost", port=8080
1:main│└┬─┬─ basic::server host="localhost"
1:main│ │ └─ port=8080
1:main│ ├─ Xms INFO basic starting
1:main│ ├─ Xs INFO basic listening
1:main│ ├┐basic::server host="localhost", port=8080
1:main│ │└┐basic::conn peer_addr="82.9.9.9", port=42381
1:main│ ├┬─┬─ basic::server host="localhost"
1:main│ ││ └─ port=8080
1:main│ │└┬─┬─ basic::conn peer_addr="82.9.9.9"
1:main│ │ │ └─ port=42381
1:main│ │ ├─ Xms DEBUG basic connected
1:main│ │ ├─┬─ Xms DEBUG basic message received
1:main│ │ │ └─ length=2
1:main│ │┌┘basic::conn peer_addr="82.9.9.9", port=42381
1:main│ ├┘basic::server host="localhost", port=8080
1:main│ ├┐basic::server host="localhost", port=8080
1:main│ │└┐basic::conn peer_addr="8.8.8.8", port=18230
1:main│ │┌┴┬─ basic::conn peer_addr="82.9.9.9"
1:main│ ││ └─ port=42381
1:main│ ├┴┬─ basic::server host="localhost"
1:main│ │ └─ port=8080
1:main│ ├┬─┬─ basic::server host="localhost"
1:main│ ││ └─ port=8080
1:main│ │└┬─┬─ basic::conn peer_addr="8.8.8.8"
1:main│ │ │ └─ port=18230
1:main│ │ ├─ Xms DEBUG basic connected
1:main│ │┌┘basic::conn peer_addr="8.8.8.8", port=18230
1:main│ ├┘basic::server host="localhost", port=8080
1:main│ ├┐basic::server host="localhost", port=8080
1:main│ │└┐basic::foomp 42 <- format string, normal_var=43
1:main│ │┌┴┬─ basic::conn peer_addr="8.8.8.8"
1:main│ ││ └─ port=18230
1:main│ ├┴┬─ basic::server host="localhost"
1:main│ │ └─ port=8080
1:main│ ├┬─┬─ basic::server host="localhost"
1:main│ ││ └─ port=8080
1:main│ │└┬─┬─ basic::foomp 42 <- format string
1:main│ │ │ └─ normal_var=43
1:main│ │ ├─ Xms ERROR basic hello
1:main│ │┌┘basic::foomp 42 <- format string, normal_var=43
1:main│ ├┘basic::server host="localhost", port=8080
1:main│ ├┐basic::server host="localhost", port=8080
1:main│ │└┐basic::conn peer_addr="82.9.9.9", port=42381
1:main│ │┌┴┬─ basic::foomp 42 <- format string
1:main│ ││ └─ normal_var=43
1:main│ ├┴┬─ basic::server host="localhost"
1:main│ │ └─ port=8080
1:main│ ├┬─┬─ basic::server host="localhost"
1:main│ ││ └─ port=8080
1:main│ │└┬─┬─ basic::conn peer_addr="82.9.9.9"
1:main│ │ │ └─ port=42381
1:main│ │ ├─┬─ Xms WARN basic weak encryption requested
1:main│ │ │ └─ algo="xor"
1:main│ │ ├─┬─ Xms DEBUG basic response sent
1:main│ │ │ └─ length=8
1:main│ │ ├─ Xms DEBUG basic disconnected
1:main│ │┌┘basic::conn peer_addr="82.9.9.9", port=42381
1:main│ ├┘basic::server host="localhost", port=8080
1:main│ ├┐basic::server host="localhost", port=8080
1:main│ │└┐basic::conn peer_addr="8.8.8.8", port=18230
1:main│ │┌┴┬─ basic::conn peer_addr="82.9.9.9"
1:main│ ││ └─ port=42381
1:main│ ├┴┬─ basic::server host="localhost"
1:main│ │ └─ port=8080
1:main│ ├┬─┬─ basic::server host="localhost"
1:main│ ││ └─ port=8080
1:main│ │└┬─┬─ basic::conn peer_addr="8.8.8.8"
1:main│ │ │ └─ port=18230
1:main│ │ ├─┬─ Xms DEBUG basic message received
1:main│ │ │ └─ length=5
1:main│ │ ├─┬─ Xms DEBUG basic response sent
1:main│ │ │ └─ length=8
1:main│ │ ├─ Xms DEBUG basic disconnected
1:main│ │┌┘basic::conn peer_addr="8.8.8.8", port=18230
1:main│ ├┘basic::server host="localhost", port=8080
1:main│ │┌┴┬─ basic::conn peer_addr="8.8.8.8"
1:main│ ││ └─ port=18230
1:main│ ├┴┬─ basic::server host="localhost"
1:main│ │ └─ port=8080
1:main│ ├─ Xs WARN basic internal error
1:main│ ├─ Xs ERROR basic this is a log message
1:main│ ├─ Xs INFO basic exit
1:main│┌┘basic::server host="localhost", port=8080
1:main│┌┴┬─ basic::server host="localhost"
1:main││ └─ port=8080
1:main├┘basic::hierarchical-example version=0.1
1:main┘basic::hierarchical-example version=0.1
18 changes: 12 additions & 6 deletions examples/quiet.stdout
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
1:main┐quiet::hierarchical-example version=0.1
1:main├─┐quiet::server host="localhost", port=8080
1:main├─┬─┬─ quiet::server host="localhost"
1:main│ │ └─ port=8080
1:main│ ├─ Xms INFO quiet starting
1:main│ ├─ Xms INFO quiet listening
1:main│ ├─┐quiet::conn peer_addr="82.9.9.9", port=42381
1:main│ ├─┬─┬─ quiet::conn peer_addr="82.9.9.9"
1:main│ │ │ └─ port=42381
1:main│ │ ├─ Xms DEBUG quiet connected
1:main│ │ ├─┬─ Xms DEBUG quiet message received
1:main│ │ │ └─ length=2
1:main│ ├─┘
1:main│ ├─┐quiet::conn peer_addr="8.8.8.8", port=18230
1:main│ ├─┬─┬─ quiet::conn peer_addr="8.8.8.8"
1:main│ │ │ └─ port=18230
1:main│ │ ├─ Xms DEBUG quiet connected
1:main│ ├─┘
1:main│ ├─┐quiet::foomp 42 <- format string, normal_var=43
1:main│ ├─┬─┬─ quiet::foomp 42 <- format string
1:main│ │ │ └─ normal_var=43
1:main│ │ ├─ Xms ERROR quiet hello
1:main│ ├─┘
1:main│ ├─┐quiet::conn peer_addr="82.9.9.9", port=42381
1:main│ ├─┬─┬─ quiet::conn peer_addr="82.9.9.9"
1:main│ │ │ └─ port=42381
1:main│ │ ├─┬─ Xms WARN quiet weak encryption requested
1:main│ │ │ └─ algo="xor"
1:main│ │ ├─┬─ Xms DEBUG quiet response sent
1:main│ │ │ └─ length=8
1:main│ │ ├─ Xms DEBUG quiet disconnected
1:main│ ├─┘
1:main│ ├─┐quiet::conn peer_addr="8.8.8.8", port=18230
1:main│ ├─┬─┬─ quiet::conn peer_addr="8.8.8.8"
1:main│ │ │ └─ port=18230
1:main│ │ ├─┬─ Xms DEBUG quiet message received
1:main│ │ │ └─ length=5
1:main│ │ ├─┬─ Xms DEBUG quiet response sent
Expand Down
101 changes: 88 additions & 13 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,18 @@ fn indent_block_with_lines(
let mut s = String::with_capacity(indent_spaces + prefix.len());
s.push_str(prefix);

// instead of using all spaces to indent, draw a vertical line at every indent level
// up until the last indent
for i in 0..(indent_spaces - indent_amount) {
let indent = |s: &mut String, i| {
if i % indent_amount == 0 {
s.push_str(LINE_VERT);
} else {
s.push(' ');
}
};

// instead of using all spaces to indent, draw a vertical line at every indent level
// up until the last indent
for i in 0..(indent_spaces - indent_amount) {
indent(&mut s, i)
}

// draw branch
Expand All @@ -310,14 +314,44 @@ fn indent_block_with_lines(
for _ in 1..(indent_amount / 2) {
buf.push_str(LINE_HORIZ);
}
buf.push_str(LINE_OPEN);
if lines.len() > 1 {
buf.push_str(ARGS_BRANCH);
for _ in 1..indent_amount {
buf.push_str(LINE_HORIZ);
}
buf.push_str(ARGS_BRANCH);
for _ in 1..indent_amount {
buf.push_str(LINE_HORIZ);
}
buf.push_str(" ");
for i in 0..(indent_amount - 1) {
indent(&mut s, i)
}
} else {
buf.push_str(LINE_OPEN);
}
}
SpanMode::Open { verbose: false } => {
buf.push_str(LINE_BRANCH);
for _ in 1..indent_amount {
buf.push_str(LINE_HORIZ);
}
buf.push_str(LINE_OPEN);
if lines.len() > 1 {
buf.push_str(ARGS_BRANCH);
for _ in 1..indent_amount {
buf.push_str(LINE_HORIZ);
}
buf.push_str(ARGS_BRANCH);
for _ in 1..indent_amount {
buf.push_str(LINE_HORIZ);
}
buf.push_str(" ");
for i in 0..indent_amount {
indent(&mut s, i)
}
} else {
buf.push_str(LINE_OPEN);
}
}
SpanMode::Open { verbose: true } => {
buf.push_str(LINE_VERT);
Expand All @@ -333,7 +367,22 @@ fn indent_block_with_lines(
}
// We don't have the space for fancy rendering at single space indent.
if indent_amount > 1 {
buf.push_str(LINE_OPEN);
if lines.len() > 1 {
buf.push_str(ARGS_BRANCH);
for _ in 1..indent_amount {
buf.push_str(LINE_HORIZ);
}
buf.push_str(ARGS_BRANCH);
for _ in 1..indent_amount {
buf.push_str(LINE_HORIZ);
}
buf.push_str(" ");
for i in 0..indent_amount {
indent(&mut s, i)
}
} else {
buf.push_str(LINE_OPEN);
}
} else {
buf.push_str(LINE_VERT);
}
Expand All @@ -359,7 +408,22 @@ fn indent_block_with_lines(
}
// We don't have the space for fancy rendering at single space indent.
if indent_amount > 1 {
buf.push_str(LINE_CLOSE);
if lines.len() > 1 {
buf.push_str("┴");
for _ in 1..indent_amount - 1 {
buf.push_str(LINE_HORIZ);
}
buf.push_str("┬");
for _ in 1..indent_amount {
buf.push_str(LINE_HORIZ);
}
buf.push_str(" ");
for i in 0..indent_amount - 1 {
indent(&mut s, i)
}
} else {
buf.push_str(LINE_CLOSE);
}
} else {
buf.push_str(LINE_VERT);
}
Expand All @@ -369,7 +433,22 @@ fn indent_block_with_lines(
for _ in 1..(indent_amount / 2) {
buf.push_str(LINE_HORIZ);
}
buf.push_str(LINE_CLOSE);
if lines.len() > 1 {
buf.push_str("┴");
for _ in 1..indent_amount - 1 {
buf.push_str(LINE_HORIZ);
}
buf.push_str("┬");
for _ in 1..indent_amount {
buf.push_str(LINE_HORIZ);
}
buf.push_str(" ");
for i in 0..indent_amount - 2 {
indent(&mut s, i)
}
} else {
buf.push_str(LINE_CLOSE);
}
}
SpanMode::Event => {
buf.push_str(LINE_BRANCH);
Expand All @@ -392,11 +471,7 @@ fn indent_block_with_lines(
// add the rest of the indentation, since we don't want to draw horizontal lines
// for subsequent lines
for i in 0..indent_amount {
if i % indent_amount == 0 {
s.push_str(LINE_VERT);
} else {
s.push(' ');
}
indent(&mut s, i)
}

// add all of the actual content, with each line preceded by the indent string
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ where
}
}
for (k, v) in kvs {
write!(buf, ", {}={}", k, v)?;
write!(buf, "\n {}={}", k, v)?;
}
Ok(())
}
Expand Down

0 comments on commit bd7a397

Please sign in to comment.