making an easy way to record and dump notes at the end of verbose setup logging, without being tied to a Timer

This commit is contained in:
Dustin Carlino 2018-12-01 13:14:54 -08:00
parent ac39985f8f
commit e75ef3f9e6
5 changed files with 29 additions and 2 deletions

View File

@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Dustin Carlino <dabreegster@gmail.com>"]
[dependencies]
lazy_static = "1.1.0"
log = "0.4.5"
multimap = "0.4.0"
rand = { version = "0.5.1", features = ["serde1"] }

View File

@ -1,3 +1,5 @@
#[macro_use]
extern crate lazy_static;
extern crate log;
extern crate multimap;
extern crate rand;
@ -13,6 +15,7 @@ mod collections;
mod error;
mod io;
mod logs;
mod notes;
mod random;
mod time;
@ -25,6 +28,7 @@ pub use io::{
write_json, FileWithProgress,
};
pub use logs::{format_log_record, LogAdapter};
pub use notes::note;
pub use random::{fork_rng, WeightedUsizeChoice};
pub use time::{elapsed_seconds, Timer};

20
abstutil/src/notes.rs Normal file
View File

@ -0,0 +1,20 @@
use std::sync::Mutex;
lazy_static! {
static ref NOTES: Mutex<Vec<String>> = Mutex::new(Vec::new());
}
pub fn note(msg: String) {
NOTES.lock().unwrap().push(msg);
}
pub fn dump_notes() {
let mut notes = NOTES.lock().unwrap();
// TODO log or println?
for msg in notes.iter() {
println!("{}", msg);
}
notes.clear();
}

View File

@ -1,3 +1,4 @@
use notes;
use std::io::{stdout, Write};
use std::time::Instant;
use PROGRESS_FREQUENCY_SECONDS;
@ -114,6 +115,7 @@ impl Timer {
}
println!("");
}
notes::dump_notes();
}
pub fn start(&mut self, name: &str) {

View File

@ -1,4 +1,4 @@
use abstutil::Error;
use abstutil::{note, Error};
use dimensioned::si;
use std;
use std::collections::BTreeSet;
@ -195,7 +195,7 @@ fn smart_assignment(map: &Map, i: IntersectionID) -> ControlTrafficSignal {
return ts;
}
Err(err) => {
error!("For {}: {}", i, err);
note(format!("For {}: {}", i, err));
}
}
}