Skip to content

Commit

Permalink
Clean up log usage
Browse files Browse the repository at this point in the history
Signed-off-by: Michael X. Grey <grey@openrobotics.org>
  • Loading branch information
mxgrey committed Jul 7, 2023
1 parent 04f00a6 commit e5f5f0b
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 49 deletions.
2 changes: 1 addition & 1 deletion rmf_site_editor/src/interaction/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn update_physical_light_visual_cues(
if let Some(m) = material_assets.get_mut(material) {
m.base_color = kind.color().into();
} else {
error!("DEV ERROR: Unable to get material asset for light");
error!("Unable to get material asset for light");
}

if kind.is_directional() {
Expand Down
48 changes: 24 additions & 24 deletions rmf_site_editor/src/interaction/select_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl TargetTransition {
Some(e) => {
if self.created.is_some() {
error!(
"DEV ERROR: Created a superfluous target while in \
"Created a superfluous target while in \
SelectAnchor mode"
);
}
Expand All @@ -175,7 +175,7 @@ impl TargetTransition {
Some(e) => Some(e),
None => {
error!(
"DEV ERROR: Failed to create an entity while in \
"Failed to create an entity while in \
SelectAnchor mode"
);
None
Expand Down Expand Up @@ -276,7 +276,7 @@ impl AnchorSelection {
Ok(dep) => dep,
Err(_) => {
// The entity was not a proper anchor
error!("DEV ERROR: Invalid anchor selected {:?}", e);
error!("Invalid anchor selected {:?}", e);
return Err(());
}
};
Expand All @@ -301,7 +301,7 @@ impl AnchorSelection {
let mut deps = match params.dependents.get_mut(*e).map_err(|_| ()) {
Ok(dep) => dep,
Err(_) => {
error!("DEV ERROR: Invalid anchor selected {:?}", e);
error!("Invalid anchor selected {:?}", e);
return Err(());
}
};
Expand Down Expand Up @@ -395,7 +395,7 @@ impl EdgePlacement {
}
Err(_) => {
error!(
"DEV ERROR: No AnchorDependents component found for \
"No AnchorDependents component found for \
{:?} while in SelectAnchor mode.",
old_anchor
);
Expand Down Expand Up @@ -436,7 +436,7 @@ impl Placement for EdgePlacement {
Ok((edge, original)) => (target, edge, original),
Err(_) => {
error!(
"DEV ERROR: Entity {:?} is not the right kind of \
"Entity {:?} is not the right kind of \
element",
target,
);
Expand Down Expand Up @@ -593,14 +593,14 @@ impl Placement for EdgePlacement {
return Ok((TargetTransition::finished(), self.to_start()).into());
} else {
error!(
"DEV ERROR: Unable to find original for {target:?} \
"Unable to find original for {target:?} \
while backing out of edge replacement"
);
return Err(());
}
} else {
error!(
"DEV ERROR: Unable to find edge for {target:?} while \
"Unable to find edge for {target:?} while \
backing out of edge replacement"
);
return Err(());
Expand Down Expand Up @@ -679,7 +679,7 @@ impl Placement for PointPlacement {
Ok(l) => l,
Err(_) => {
error!(
"DEV ERROR: Unable to get location {:?} while in \
"Unable to get location {:?} while in \
SelectAnchor mode.",
target
);
Expand Down Expand Up @@ -765,7 +765,7 @@ impl Placement for PointPlacement {
}
} else {
error!(
"DEV ERROR: Cannot find point for location {target:?} while \
"Cannot find point for location {target:?} while \
trying to back out of SelectAnchor mode"
);
return Err(());
Expand Down Expand Up @@ -863,7 +863,7 @@ impl Placement for PathPlacement {
Ok(q) => q,
Err(_) => {
error!(
"DEV ERROR: Unable to find path info for {target:?} while \
"Unable to find path info for {target:?} while \
in SelectAnchor mode."
);
return Err(());
Expand Down Expand Up @@ -933,7 +933,7 @@ impl Placement for PathPlacement {
Ok(p) => p.0,
Err(_) => {
error!(
"DEV ERROR: Unable to find path for {:?} while in \
"Unable to find path for {:?} while in \
SelectAnchor mode",
target,
);
Expand All @@ -953,7 +953,7 @@ impl Placement for PathPlacement {
Ok(p) => p.0.clone(),
Err(_) => {
error!(
"DEV ERROR: Unable to find path for {:?} while in \
"Unable to find path for {:?} while in \
SelectAnchor mode",
target,
);
Expand Down Expand Up @@ -989,7 +989,7 @@ impl Placement for PathPlacement {
}

error!(
"DEV ERROR: Path of length {} is missing the index {} \
"Path of length {} is missing the index {} \
that was supposed to be replaced.",
path.len(),
index
Expand All @@ -998,7 +998,7 @@ impl Placement for PathPlacement {
}

error!(
"DEV ERROR: Unable to find the placement of a path anchor \
"Unable to find the placement of a path anchor \
that is being replaced."
);
return Err(());
Expand Down Expand Up @@ -1082,7 +1082,7 @@ impl<'w, 's> SelectAnchorPlacementParams<'w, 's> {
Ok(dep) => dep,
Err(_) => {
error!(
"DEV ERROR: Trying to insert invalid anchor \
"Trying to insert invalid anchor \
{to_anchor:?} into entity {dependent:?}"
);
return Err(());
Expand All @@ -1108,7 +1108,7 @@ impl<'w, 's> SelectAnchorPlacementParams<'w, 's> {
Ok(dep) => dep,
Err(_) => {
error!(
"DEV ERROR: Removing invalid anchor {from_anchor:?} \
"Removing invalid anchor {from_anchor:?} \
from entity {dependent:?}"
);
return Err(());
Expand Down Expand Up @@ -1433,7 +1433,7 @@ impl SelectAnchor {
self.placement.finalize(finished_target, params);
} else {
error!(
"DEV ERROR: An element was supposed to be finished by \
"An element was supposed to be finished by \
SelectAnchor, but we could not find it"
);
}
Expand Down Expand Up @@ -1666,7 +1666,7 @@ impl SelectAnchor3D {
Ok(l) => l,
Err(_) => {
error!(
"DEV ERROR: Unable to get anchor {:?} while \
"Unable to get anchor {:?} while \
replacing 3D Anchor.",
target
);
Expand Down Expand Up @@ -1722,7 +1722,7 @@ impl SelectAnchor3D {
return Ok(());
}
None => {
error!("DEV ERROR: Reassigning parent for entity without a parent");
error!("Reassigning parent for entity without a parent");
return Err(());
}
}
Expand Down Expand Up @@ -1791,7 +1791,7 @@ impl SelectAnchor3D {
}
} else {
error!(
"DEV ERROR: Cannot find point for location {target:?} while \
"Cannot find point for location {target:?} while \
trying to back out of SelectAnchor mode"
);
return Err(());
Expand Down Expand Up @@ -1903,7 +1903,7 @@ pub fn handle_select_anchor_mode(
Some(for_element) => for_element,
None => {
error!(
"DEV ERROR: for_element must be Some for ReplaceAnchor. \
"for_element must be Some for ReplaceAnchor. \
Reverting to Inspect Mode."
);
params.cleanup();
Expand All @@ -1916,7 +1916,7 @@ pub fn handle_select_anchor_mode(
Some(original) => original,
None => {
error!(
"DEV ERROR: cannot locate an original anchor for \
"cannot locate an original anchor for \
entity {:?}. Reverting to Inspect Mode.",
for_element,
);
Expand Down Expand Up @@ -1961,7 +1961,7 @@ pub fn handle_select_anchor_mode(
Ok(tf) => tf,
Err(_) => {
error!(
"DEV ERROR: Could not get transform for cursor frame \
"Could not get transform for cursor frame \
{:?} in SelectAnchor mode.",
params.cursor.frame,
);
Expand Down
1 change: 1 addition & 0 deletions rmf_site_editor/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl Default for LogHistory {
filter_hashmap.insert(LogCategory::Warning, true);
filter_hashmap.insert(LogCategory::Error, true);
filter_hashmap.insert(LogCategory::Bevy, false);
filter_hashmap.insert(LogCategory::Hint, true);

let (tx, rx) = unbounded();
let tx_2 = tx.clone();
Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/src/site/change_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn update_changed_values<T: Component + Clone + Debug>(
.insert(change.to_value.clone());
} else {
error!(
"DEV ERROR: Unable to change {} data to {:?} for entity {:?} \
"Unable to change {} data to {:?} for entity {:?} \
because the entity does not have that type",
std::any::type_name::<T>(),
change.to_value,
Expand Down
26 changes: 14 additions & 12 deletions rmf_site_editor/src/site/deletion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

use crate::{
log::Log,
interaction::{Select, Selection},
site::{Category, CurrentLevel, Dependents, LevelProperties, SiteUpdateStage},
};
Expand Down Expand Up @@ -86,6 +87,7 @@ struct DeletionParams<'w, 's> {
current_level: ResMut<'w, CurrentLevel>,
levels: Query<'w, 's, Entity, With<LevelProperties>>,
select: EventWriter<'w, 's, Select>,
log: EventWriter<'w, 's, Log>,
}

pub struct DeletionPlugin;
Expand Down Expand Up @@ -128,16 +130,16 @@ fn cautious_delete(element: Entity, params: &mut DeletionParams) {
for descendent in &all_descendents {
if let Ok(prevent) = params.preventions.get(*descendent) {
if *descendent == element {
warn!(
params.log.send(Log::hint(format!(
"Element {:?} cannot be deleted because: {}",
element,
prevent
.reason
.as_ref()
.unwrap_or(&"<.. no reason given>".to_string()),
);
)));
} else {
warn!(
params.log.send(Log::hint(format!(
"Element {:?} is an ancestor of {:?} which cannot be \
deleted because: {}",
element,
Expand All @@ -146,7 +148,7 @@ fn cautious_delete(element: Entity, params: &mut DeletionParams) {
.reason
.as_ref()
.unwrap_or(&"<.. no reason given>".to_string()),
);
)));
}
return;
}
Expand All @@ -155,20 +157,20 @@ fn cautious_delete(element: Entity, params: &mut DeletionParams) {
for dep in dependents.iter() {
if !all_descendents.contains(dep) {
if *descendent == element {
warn!(
params.log.send(Log::hint(format!(
"Cannot delete {:?} because it has {} dependents. \
Only elements with no outside dependents can be \
deleted.",
element,
dependents.len(),
);
)));
} else {
warn!(
params.log.send(Log::hint(format!(
"Element {:?} is an ancestor of {:?} \
which cannot be deleted because {:?} depends \
on it.",
element, descendent, dep,
);
)));
}
return;
}
Expand Down Expand Up @@ -238,16 +240,16 @@ fn recursive_dependent_delete(element: Entity, params: &mut DeletionParams) {
while let Some(top) = queue.pop() {
if let Ok(prevent) = params.preventions.get(top) {
if top == element {
warn!(
params.log.send(Log::hint(format!(
"Cannot delete {:?} because: {}",
element,
prevent
.reason
.as_ref()
.unwrap_or(&"<.. no reason given>".to_string()),
);
)));
} else {
warn!(
params.log.send(Log::hint(format!(
"Cannot delete {:?} because we would need to also delete \
{:?} which cannot be deleted because: {}",
element,
Expand All @@ -256,7 +258,7 @@ fn recursive_dependent_delete(element: Entity, params: &mut DeletionParams) {
.reason
.as_ref()
.unwrap_or(&"<.. no reason given>".to_string()),
)
)));
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion rmf_site_editor/src/site/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn handle_loaded_drawing(
if let Ok(mut mesh_handle) = mesh_handles.get_mut(segment.leaf) {
*mesh_handle = mesh;
} else {
error!("DEV ERROR: Partially-constructed Drawing entity detected");
error!("Partially-constructed Drawing entity detected");
}
// We can ignore the layer height here since that update
// will be handled by another system.
Expand Down
4 changes: 2 additions & 2 deletions rmf_site_editor/src/site/floor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn make_floor_mesh(entity: Entity, anchor_path: &Path<Entity>, anchors: &AnchorP
if let Ok(p) = anchors.point_in_parent_frame_of(*anchor, Category::Floor, entity) {
positions.push(p);
} else {
error!("DEV ERROR: Failed to find anchor {anchor:?} used by a path");
error!("Failed to find anchor {anchor:?} used by a path");
valid = false;
}
}
Expand All @@ -187,7 +187,7 @@ fn make_floor_mesh(entity: Entity, anchor_path: &Path<Entity>, anchors: &AnchorP
let p = match anchors.point_in_parent_frame_of(*anchor, Category::Floor, entity) {
Ok(a) => a,
Err(_) => {
error!("DEV ERROR: Failed to find anchor {anchor:?} used by a path");
error!("Failed to find anchor {anchor:?} used by a path");
valid = false;
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions rmf_site_editor/src/site/lift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub fn update_lift_door_availability(
// If we're being asked to toggle availability on for something
// that isn't a level, then ignore this request.
error!(
"DEV ERROR: Asking to turn on lift {:?} door {:?} availability \
"Asking to turn on lift {:?} door {:?} availability \
for a level {:?} that does not exist.",
toggle.for_lift, toggle.cabin_door, toggle.on_level,
);
Expand Down Expand Up @@ -532,7 +532,7 @@ pub fn update_lift_door_availability(
Ok(e_lift) => e_lift,
Err(_) => {
error!(
"DEV ERROR: Unable to find parent for lift door \
"Unable to find parent for lift door \
{e_door:?} while handling a removed level"
);
continue;
Expand All @@ -541,7 +541,7 @@ pub fn update_lift_door_availability(
let (mut cabin, _, _) = match lifts.get_mut(e_lift.get()) {
Ok(cabin) => cabin,
Err(_) => {
error!("DEV ERROR: Unable to find cabin for lift {e_lift:?}");
error!("Unable to find cabin for lift {e_lift:?}");
continue;
}
};
Expand Down
Loading

0 comments on commit e5f5f0b

Please sign in to comment.