Skip to content

Commit 56e2a2f

Browse files
authored
Re-enabled hierarchical logs in the compiler (#3449)
We reverted the hierarchical logs a while ago (#2581) due to an outdated dependency that has since been fixed. I think this makes the logs much more readable, by indenting the logs given the scope. More than one scope makes the lines way too long, which I think it's harder to read. This is how the logs look without this change: ``` 2024-08-17T02:42:21.874979Z DEBUG CodegenFunction{name="kani::assert"}: kani_compiler::codegen_cprover_gotoc::utils::debug: handling kani::assert 2024-08-17T02:42:21.875008Z DEBUG CodegenFunction{name="kani::assert"}: kani_compiler::codegen_cprover_gotoc::utils::debug: variables: 2024-08-17T02:42:21.875026Z DEBUG CodegenFunction{name="kani::assert"}: kani_compiler::codegen_cprover_gotoc::utils::debug: let _0: Ty { id: 4, kind: RigidTy(Tuple([])) } ``` This is how it looks after this change: ``` ┐kani_compiler::codegen_cprover_gotoc::codegen::function::CodegenFunction name="kani::assert" ├─── DEBUG kani_compiler::codegen_cprover_gotoc::utils::debug handling kani::assert ├─── DEBUG kani_compiler::codegen_cprover_gotoc::utils::debug variables: ├─── DEBUG kani_compiler::codegen_cprover_gotoc::utils::debug let _0: Ty { id: 4, kind: RigidTy(Tuple([])) } ├─── DEBUG kani_compiler::codegen_cprover_gotoc::utils::debug let _1: Ty { id: 6, kind: RigidTy(Bool) } ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 0ed9a62 commit 56e2a2f

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Cargo.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ dependencies = [
475475
"strum_macros",
476476
"tracing",
477477
"tracing-subscriber",
478+
"tracing-tree",
478479
]
479480

480481
[[package]]
@@ -617,6 +618,15 @@ dependencies = [
617618
"winapi",
618619
]
619620

621+
[[package]]
622+
name = "nu-ansi-term"
623+
version = "0.50.1"
624+
source = "registry+https://github.com/rust-lang/crates.io-index"
625+
checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399"
626+
dependencies = [
627+
"windows-sys 0.52.0",
628+
]
629+
620630
[[package]]
621631
name = "num"
622632
version = "0.4.3"
@@ -1263,7 +1273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
12631273
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
12641274
dependencies = [
12651275
"matchers",
1266-
"nu-ansi-term",
1276+
"nu-ansi-term 0.46.0",
12671277
"once_cell",
12681278
"parking_lot",
12691279
"regex",
@@ -1278,6 +1288,18 @@ dependencies = [
12781288
"tracing-serde",
12791289
]
12801290

1291+
[[package]]
1292+
name = "tracing-tree"
1293+
version = "0.4.0"
1294+
source = "registry+https://github.com/rust-lang/crates.io-index"
1295+
checksum = "f459ca79f1b0d5f71c54ddfde6debfc59c8b6eeb46808ae492077f739dc7b49c"
1296+
dependencies = [
1297+
"nu-ansi-term 0.50.1",
1298+
"tracing-core",
1299+
"tracing-log",
1300+
"tracing-subscriber",
1301+
]
1302+
12811303
[[package]]
12821304
name = "unicode-ident"
12831305
version = "1.0.12"

kani-compiler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ strum_macros = "0.26"
2424
shell-words = "1.0.0"
2525
tracing = {version = "0.1", features = ["max_level_trace", "release_max_level_debug"]}
2626
tracing-subscriber = {version = "0.3.8", features = ["env-filter", "json", "fmt"]}
27+
tracing-tree = "0.4.0"
2728

2829
# Future proofing: enable backend dependencies using feature.
2930
[features]

kani-compiler/src/session.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::io::IsTerminal;
1919
use std::panic;
2020
use std::sync::LazyLock;
2121
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
22+
use tracing_tree::HierarchicalLayer;
2223

2324
/// Environment variable used to control this session log tracing.
2425
const LOG_ENV_VAR: &str = "KANI_LOG";
@@ -114,10 +115,13 @@ fn hier_logs(args: &Arguments, filter: EnvFilter) {
114115
let use_colors = std::io::stdout().is_terminal() || args.color_output;
115116
let subscriber = Registry::default().with(filter);
116117
let subscriber = subscriber.with(
117-
tracing_subscriber::fmt::layer()
118+
HierarchicalLayer::default()
118119
.with_writer(std::io::stderr)
120+
.with_indent_lines(true)
119121
.with_ansi(use_colors)
120-
.with_target(true),
122+
.with_targets(true)
123+
.with_verbose_exit(true)
124+
.with_indent_amount(4),
121125
);
122126
tracing::subscriber::set_global_default(subscriber).unwrap();
123127
}

0 commit comments

Comments
 (0)