Skip to content

Commit cee0cca

Browse files
committed
dv: DV_LOG=debug DV_LOG_FILE=$PWD/dv.log ./.github/gen_core.json.sh
add log file support
1 parent 58b34c8 commit cee0cca

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

.github/gen_core.json.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export VERIFY_RUST_STD_LIBRARY=$WORKSPACE/verify-rust-std/library
1212
# test/verify-rust-std needs this, so remember to
1313
# * update runid after verify-rust-std submodule syncs
1414
# * update snapshots after runid changes
15-
rm tmp -rf
16-
gh run download -D tmp -R model-checking/verify-rust-std 16777123952
15+
# rm tmp -rf
16+
# gh run download -D tmp -R model-checking/verify-rust-std 16777123952
1717

1818
ls -alh $VERIFY_RUST_STD_LIBRARY
1919

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ core.json
1313
*.sqlite3
1414
*.db
1515
*.diff
16+
*.log
1617

1718
tmp/

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ eyre = "0.6"
1717
color-eyre = "0.6"
1818

1919
# logger
20+
log = "0.4.27"
2021
tracing = "0.1"
2122
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
2223
tracing-error = "0.2"

src/bin/distributed-verification/functions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod utils;
1818
pub fn analyze(tcx: TyCtxt) -> Vec<SerFunction> {
1919
let local_items = all_local_items();
2020
let cap = local_items.len();
21+
dbg!(cap);
2122

2223
let mut entries = Vec::with_capacity(cap);
2324

src/logger.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,47 @@
1+
use std::{env, fs};
12
use tracing_subscriber::{EnvFilter, fmt, prelude::*, registry};
23

4+
const ENV_LOG: &str = "DV_LOG";
5+
const ENV_LOG_FILE: &str = "DV_LOG_FILE";
6+
37
pub fn init() {
4-
// let fmt_layer = fmt::layer();
58
let fmt_layer = fmt::layer()
69
.with_line_number(false)
710
.with_level(false)
811
.without_time()
912
.with_file(false)
1013
.with_target(false);
11-
let env_layer = EnvFilter::from_default_env();
14+
15+
let env_layer = EnvFilter::from_env(ENV_LOG);
1216
let error_layer = tracing_error::ErrorLayer::default();
1317

14-
if let Err(err) = registry().with(env_layer).with(error_layer).with(fmt_layer).try_init() {
18+
let reg = registry().with(env_layer).with(error_layer);
19+
20+
// When DV_LOG and DV_LOG_FILE are specified and the file exists,
21+
// append logs into the file. The reason to append rather than
22+
// write logs is keeping records across the whole compilation.
23+
let reg = if let Some(log_file) = env::var(ENV_LOG)
24+
.map(|log| {
25+
log.parse::<log::Level>().ok()?;
26+
log_file()
27+
})
28+
.ok()
29+
.flatten()
30+
{
31+
let fmt_layer = fmt_layer.with_writer(log_file);
32+
reg.with(fmt_layer).try_init()
33+
} else {
34+
reg.with(fmt_layer).try_init()
35+
};
36+
37+
if let Err(err) = reg {
1538
eprintln!("Logger already init: {err}");
1639
};
1740

1841
color_eyre::install().unwrap();
1942
}
43+
44+
fn log_file() -> Option<fs::File> {
45+
let file = env::var(ENV_LOG_FILE).ok()?;
46+
fs::OpenOptions::new().append(true).open(file).ok()
47+
}

0 commit comments

Comments
 (0)