logging in map layer too

This commit is contained in:
Dustin Carlino 2018-09-23 14:13:32 -07:00
parent a53dd51ec4
commit 09c3b017b9
13 changed files with 74 additions and 27 deletions

View File

@ -99,6 +99,7 @@ nice UI features:
- jump to end or beginning quickly
- start at the end
- show new messages in OSD briefly, then vanish
- wrap long lines
log crate is annoying -- cant initialize it, but also have something else hold
onto it. probably have to use lazy static. not even sure I'll use this implicit

View File

@ -10,6 +10,7 @@ flame = "0.2.2"
geo = "0.9.1"
geom = { path = "../geom" }
gtfs = { path = "../gtfs" }
log = "0.4.5"
multimap = "0.4.0"
ordered-float = "0.5.0"
pretty_assertions = "0.5.1"

View File

@ -62,7 +62,7 @@ impl RoadEdit {
new_type: LaneType,
) -> Option<RoadEdit> {
if lane.is_sidewalk() {
println!("Sidewalks are fixed; can't change their type");
error!("Sidewalks are fixed; can't change their type");
return None;
}
@ -70,7 +70,7 @@ impl RoadEdit {
let (is_fwd, idx) = r.dir_and_offset(lane.id);
if is_fwd {
if forwards[idx] == new_type {
println!("{} is already {:?}", lane.id, new_type);
error!("{} is already {:?}", lane.id, new_type);
return None;
}
forwards[idx] = new_type;
@ -79,7 +79,7 @@ impl RoadEdit {
}
} else {
if backwards[idx] == new_type {
println!("{} is already {:?}", lane.id, new_type);
error!("{} is already {:?}", lane.id, new_type);
return None;
}
backwards[idx] = new_type;
@ -99,7 +99,7 @@ impl RoadEdit {
fn delete_lane(r: &Road, lane: &Lane) -> Option<RoadEdit> {
// Sidewalks are fixed
if lane.is_sidewalk() {
println!("Can't delete sidewalks");
error!("Can't delete sidewalks");
return None;
}
@ -124,14 +124,14 @@ fn are_lanes_valid(lanes: &Vec<LaneType>) -> bool {
// TODO this check doesn't seem to be working
for pair in lanes.windows(2) {
if pair[0] == LaneType::Parking && pair[1] == LaneType::Parking {
println!("Can't have two adjacent parking lanes");
error!("Can't have two adjacent parking lanes");
return false;
}
}
// Can't have two sidewalks on one side of a road
if lanes.iter().filter(|&&lt| lt == LaneType::Sidewalk).count() > 1 {
println!("Can't have two sidewalks on one side of a road");
error!("Can't have two sidewalks on one side of a road");
return false;
}

View File

@ -4,6 +4,8 @@ extern crate flame;
extern crate geo;
extern crate geom;
extern crate gtfs;
#[macro_use]
extern crate log;
extern crate multimap;
extern crate ordered_float;
#[macro_use]
@ -12,6 +14,9 @@ extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
mod macros;
mod area;
mod building;
mod bus_stop;

37
map_model/src/macros.rs Normal file
View File

@ -0,0 +1,37 @@
// Call the log crate, but pre-set the target.
macro_rules! debug {
( $( $x:expr ),* ) => {
{
extern crate log;
log!(target: "map", log::Level::Debug, $( $x, )* );
}
}
}
macro_rules! info {
( $( $x:expr ),* ) => {
{
extern crate log;
log!(target: "map", log::Level::Info, $( $x, )* );
}
}
}
macro_rules! warn {
( $( $x:expr ),* ) => {
{
extern crate log;
log!(target: "map", log::Level::Warn, $( $x, )* );
}
}
}
macro_rules! error {
( $( $x:expr ),* ) => {
{
extern crate log;
log!(target: "map", log::Level::Error, $( $x, )* );
}
}
}

View File

@ -56,7 +56,7 @@ pub(crate) fn make_all_buildings(
let discarded = input.len() - results.len();
if discarded > 0 {
println!(
info!(
"Discarded {} buildings that weren't close enough to a sidewalk",
discarded
);

View File

@ -50,7 +50,7 @@ pub fn make_bus_stops(
);
}
} else {
println!(
warn!(
"Can't find driving lane next to {}: {:?} and {:?}",
id, road.children_forwards, road.children_backwards
);
@ -65,7 +65,10 @@ pub fn make_bus_stops(
.map(|stop| *stop)
.collect();
if stops.len() == 1 {
//println!("Skipping route {} since it only has 1 stop in the slice of the map", route_name);
debug!(
"Skipping route {} since it only has 1 stop in the slice of the map",
route_name
);
continue;
}
routes.push(BusRoute {

View File

@ -77,7 +77,7 @@ impl LaneSpec {
pub(crate) fn get_lane_specs(r: &raw_data::Road, id: RoadID, edits: &Edits) -> Vec<LaneSpec> {
let (side1_types, side2_types) = if let Some(e) = edits.roads.get(&id) {
println!("Using edits for {}", id);
info!("Using edits for {}", id);
(e.forwards_lanes.clone(), e.backwards_lanes.clone())
} else {
get_lanes(r)

View File

@ -46,7 +46,7 @@ pub(crate) fn make_all_parcels(
}
let discarded = input.len() - results.len();
if discarded > 0 {
println!(
info!(
"Discarded {} parcels that weren't close enough to a sidewalk",
discarded
);

View File

@ -45,7 +45,7 @@ pub(crate) fn trim_lines(lanes: &mut Vec<Lane>, i: &Intersection) {
// TODO how does this happen?
if pl1 == pl2 {
println!("Both {} and {} have same pts?! {}", incoming, outgoing, pl1);
error!("Both {} and {} have same pts?! {}", incoming, outgoing, pl1);
continue;
}

View File

@ -17,7 +17,7 @@ fn dedupe(turns: Vec<Turn>) -> Vec<Turn> {
for t in turns.into_iter() {
if ids.contains(&t.id) {
// TODO Disable panic so large.abst works :(
println!("Duplicate turns {}!", t.id);
error!("Duplicate turns {}!", t.id);
} else {
ids.insert(t.id);
keep.push(t);
@ -113,13 +113,13 @@ fn make_turns(
// TODO: Figure out why this happens in the huge map
if incoming.is_empty() {
if false {
println!("WARNING: {} has no incoming lanes of some type", parent);
warn!("{} has no incoming lanes of some type", parent);
}
return Vec::new();
}
if outgoing.is_empty() {
if false {
println!("WARNING: {} has no outgoing lanes of some type", parent);
warn!("{} has no outgoing lanes of some type", parent);
}
return Vec::new();
}

View File

@ -701,12 +701,12 @@ impl DrivingSimState {
{
let other_dist = self.cars[&other].dist_along;
if other_dist >= dist_along {
debug!(
"{} can't spawn, because they'd wind up too close ({}) behind {}",
car,
other_dist - dist_along,
other
);
debug!(
"{} can't spawn, because they'd wind up too close ({}) behind {}",
car,
other_dist - dist_along,
other
);
return false;
}
@ -720,7 +720,7 @@ impl DrivingSimState {
0.0 * si::MPS,
).unwrap();
if accel_for_other_to_stop <= other_vehicle.max_deaccel {
debug!("{} can't spawn {} in front of {}, because {} would have to do {} to not hit {}", car, dist_along - other_dist, other, other, accel_for_other_to_stop, car);
debug!("{} can't spawn {} in front of {}, because {} would have to do {} to not hit {}", car, dist_along - other_dist, other, other, accel_for_other_to_stop, car);
return false;
}

View File

@ -145,11 +145,11 @@ impl Spawner {
);
}
}
debug!(
"Spawned {} agents of requested {}",
spawned_agents,
requested_paths.len()
);
debug!(
"Spawned {} agents of requested {}",
spawned_agents,
requested_paths.len()
);
}
// This happens immediately; it isn't scheduled.