From 6632b7ff73507fb35e59d67cb356009427c64f87 Mon Sep 17 00:00:00 2001 From: Jiangeng Dong Date: Wed, 31 May 2023 14:20:54 -0700 Subject: [PATCH 1/3] int: replace the (e)println! with log --- r2r/Cargo.toml | 1 + r2r/src/action_clients.rs | 22 ++++++++-------- r2r/src/action_clients_untyped.rs | 20 +++++++-------- r2r/src/action_servers.rs | 36 +++++++++++++------------- r2r/src/clients.rs | 12 ++++----- r2r/src/clocks.rs | 4 +-- r2r/src/lib.rs | 2 +- r2r/src/msg_types.rs | 42 +++++++++++++++---------------- r2r/src/nodes.rs | 14 +++++------ r2r/src/parameters.rs | 2 +- r2r/src/publishers.rs | 14 +++++------ r2r/src/services.rs | 2 +- r2r/src/subscribers.rs | 6 ++--- r2r/src/utils.rs | 2 +- 14 files changed, 90 insertions(+), 89 deletions(-) diff --git a/r2r/Cargo.toml b/r2r/Cargo.toml index 913502daa..b474f800e 100644 --- a/r2r/Cargo.toml +++ b/r2r/Cargo.toml @@ -24,6 +24,7 @@ r2r_msg_gen = { path = "../r2r_msg_gen", version = "0.3.11" } r2r_actions = { path = "../r2r_actions", version = "0.3.10" } uuid = { version = "1.2.2", features = ["serde", "v4"] } futures = "0.3.25" +log = "0.4.18" [dev-dependencies] serde_json = "1.0.89" diff --git a/r2r/src/action_clients.rs b/r2r/src/action_clients.rs index f37834c42..49479c65e 100644 --- a/r2r/src/action_clients.rs +++ b/r2r/src/action_clients.rs @@ -164,7 +164,7 @@ where }); Ok(future) } else { - eprintln!("coult not send goal request {}", result); + log::error!("could not send goal request {}", result); Err(Error::from_rcl_error(result)) } } @@ -260,7 +260,7 @@ where }); Ok(future) } else { - eprintln!("coult not send goal request {}", result); + log::error!("could not send goal request {}", result); Err(Error::from_rcl_error(result)) } } @@ -300,7 +300,7 @@ where match sender.send((accept, stamp)) { Ok(()) => {} Err(e) => { - println!("error sending to action client: {:?}", e); + log::debug!("error sending to action client: {:?}", e); } } } else { @@ -310,7 +310,7 @@ where .map(|(id, _)| id.to_string()) .collect::>() .join(","); - eprintln!( + log::error!( "no such req id: {}, we have [{}], ignoring", request_id.sequence_number, we_have ); @@ -339,7 +339,7 @@ where let (_, sender) = self.cancel_response_channels.swap_remove(idx); let response = action_msgs::srv::CancelGoal::Response::from_native(&response_msg); if let Err(e) = sender.send(response) { - eprintln!("warning: could not send cancel response msg ({:?})", e) + log::error!("warning: could not send cancel response msg ({:?})", e) } } else { let we_have: String = self @@ -348,7 +348,7 @@ where .map(|(id, _)| id.to_string()) .collect::>() .join(","); - eprintln!( + log::error!( "no such req id: {}, we have [{}], ignoring", request_id.sequence_number, we_have ); @@ -370,7 +370,7 @@ where .find(|(uuid, _)| uuid == &msg_uuid) { if let Err(e) = sender.try_send(feedback) { - eprintln!("warning: could not send feedback msg ({})", e) + log::error!("warning: could not send feedback msg ({})", e) } } } @@ -426,7 +426,7 @@ where match sender.send((status, result)) { Ok(()) => {} Err(e) => { - println!("error sending result to action client: {:?}", e); + log::debug!("error sending result to action client: {:?}", e); } } } @@ -437,7 +437,7 @@ where .map(|(id, _)| id.to_string()) .collect::>() .join(","); - eprintln!( + log::error!( "no such req id: {}, we have [{}], ignoring", request_id.sequence_number, we_have ); @@ -461,7 +461,7 @@ where if result == RCL_RET_OK as i32 { self.result_requests.push((seq_no, uuid)); } else { - eprintln!("coult not send request {}", result); + log::error!("could not send request {}", result); } } @@ -576,7 +576,7 @@ pub fn action_server_available_helper( if result == RCL_RET_OK as i32 { Ok(avail) } else { - eprintln!("coult not check if action server is available {}", result); + log::error!("could not check if action server is available {}", result); Err(Error::from_rcl_error(result)) } } diff --git a/r2r/src/action_clients_untyped.rs b/r2r/src/action_clients_untyped.rs index 6e6278514..3239f46e2 100644 --- a/r2r/src/action_clients_untyped.rs +++ b/r2r/src/action_clients_untyped.rs @@ -153,7 +153,7 @@ impl ActionClientUntyped { }); Ok(future) } else { - eprintln!("coult not send goal request {}", result); + log::error!("could not send goal request {}", result); Err(Error::from_rcl_error(result)) } } @@ -227,7 +227,7 @@ impl WrappedActionClientUntyped { }); Ok(future) } else { - eprintln!("coult not send goal request {}", result); + log::error!("could not send goal request {}", result); Err(Error::from_rcl_error(result)) } } @@ -262,7 +262,7 @@ impl ActionClient_ for WrappedActionClientUntyped { match sender.send((accept, stamp)) { Ok(()) => {} Err(e) => { - println!("error sending to action client: {:?}", e); + log::debug!("error sending to action client: {:?}", e); } } } else { @@ -272,7 +272,7 @@ impl ActionClient_ for WrappedActionClientUntyped { .map(|(id, _)| id.to_string()) .collect::>() .join(","); - eprintln!( + log::error!( "no such req id: {}, we have [{}], ignoring", request_id.sequence_number, we_have ); @@ -301,7 +301,7 @@ impl ActionClient_ for WrappedActionClientUntyped { let (_, sender) = self.cancel_response_channels.swap_remove(idx); let response = action_msgs::srv::CancelGoal::Response::from_native(&response_msg); if let Err(e) = sender.send(response) { - eprintln!("warning: could not send cancel response msg ({:?})", e) + log::error!("warning: could not send cancel response msg ({:?})", e) } } else { let we_have: String = self @@ -310,7 +310,7 @@ impl ActionClient_ for WrappedActionClientUntyped { .map(|(id, _)| id.to_string()) .collect::>() .join(","); - eprintln!( + log::error!( "no such req id: {}, we have [{}], ignoring", request_id.sequence_number, we_have ); @@ -332,7 +332,7 @@ impl ActionClient_ for WrappedActionClientUntyped { .find(|(uuid, _)| uuid == &msg_uuid) { if let Err(e) = sender.try_send(feedback) { - eprintln!("warning: could not send feedback msg ({})", e) + log::error!("warning: could not send feedback msg ({})", e) } } } @@ -385,7 +385,7 @@ impl ActionClient_ for WrappedActionClientUntyped { match sender.send((status, result)) { Ok(()) => {} Err(e) => { - println!("error sending result to action client: {:?}", e); + log::debug!("error sending result to action client: {:?}", e); } } } @@ -396,7 +396,7 @@ impl ActionClient_ for WrappedActionClientUntyped { .map(|(id, _)| id.to_string()) .collect::>() .join(","); - eprintln!( + log::error!( "no such req id: {}, we have [{}], ignoring", request_id.sequence_number, we_have ); @@ -417,7 +417,7 @@ impl ActionClient_ for WrappedActionClientUntyped { if result == RCL_RET_OK as i32 { self.result_requests.push((seq_no, uuid)); } else { - eprintln!("coult not send request {}", result); + log::error!("could not send request {}", result); } } diff --git a/r2r/src/action_servers.rs b/r2r/src/action_servers.rs index 3d0f39776..80d2f7dc0 100644 --- a/r2r/src/action_servers.rs +++ b/r2r/src/action_servers.rs @@ -44,13 +44,13 @@ impl ActionServerCancelRequest { /// Accepts the cancel request. The action server should now cancel the corresponding goal. pub fn accept(self) { if self.response_sender.send((self.uuid, true)).is_err() { - eprintln!("warning: could not send goal canellation accept msg") + log::error!("warning: could not send goal canellation accept msg") } } /// Rejects the cancel request. pub fn reject(self) { if self.response_sender.send((self.uuid, false)).is_err() { - eprintln!("warning: could not send goal cancellation rejection") + log::error!("warning: could not send goal cancellation rejection") } } } @@ -195,7 +195,7 @@ where let ret = unsafe { rcl_action_goal_handle_get_status(*handle, &mut state) }; if ret != RCL_RET_OK as i32 { - println!("action server: Failed to get goal handle state: {}", ret); + log::debug!("action server: Failed to get goal handle state: {}", ret); return Err(Error::from_rcl_error(ret)); } return Ok(state == action_msgs::msg::GoalStatus::STATUS_CANCELING as u8); @@ -213,7 +213,7 @@ where }; if ret != RCL_RET_OK as i32 { - println!( + log::debug!( "action server: could not cancel goal: {}", Error::from_rcl_error(ret) ); @@ -239,7 +239,7 @@ where unsafe { rcl_action_server_goal_exists(self.handle(), &*goal_info_native) }; if !goal_exists { - println!("tried to publish result without a goal"); + log::debug!("tried to publish result without a goal"); return Err(Error::RCL_RET_ACTION_GOAL_HANDLE_INVALID); } @@ -286,7 +286,7 @@ where }); } Err(oneshot::Canceled) => { - eprintln!("Warning, cancel request not handled!"); + log::error!("Warning, cancel request not handled!"); return false; // skip this request. } } @@ -325,7 +325,7 @@ where }; if ret != RCL_RET_OK as i32 { - println!("action server: could send cancel response. {}", ret); + log::debug!("action server: could send cancel response. {}", ret); } } } @@ -364,7 +364,7 @@ where // send out request. if let Err(e) = self.goal_request_sender.try_send(gr) { - eprintln!("warning: could not send service request ({})", e) + log::error!("warning: could not send service request ({})", e) } } @@ -392,7 +392,7 @@ where }; if ret != RCL_RET_OK as i32 { - println!("action server: could not process cancel request. {}", ret); + log::debug!("action server: could not process cancel request. {}", ret); return; } @@ -414,7 +414,7 @@ where }; match cancel_sender.try_send(cr) { Err(_) => { - eprintln!("warning: could not send goal cancellation request"); + log::error!("warning: could not send goal cancellation request"); None } _ => Some(r), @@ -438,12 +438,12 @@ where rcl_action_expire_goals(&self.rcl_handle, &mut *goal_info, 1, &mut num_expired) }; if ret != RCL_RET_OK as i32 { - println!("action server: could not expire goal."); + log::debug!("action server: could not expire goal."); return; } let gi = action_msgs::msg::GoalInfo::from_native(&goal_info); let uuid = uuid_msg_to_uuid(&gi.goal_id); - println!("goal expired: {} - {}", uuid, num_expired); + log::debug!("goal expired: {} - {}", uuid, num_expired); // todo // self.goals.remove(&uuid); self.result_msgs.remove(&uuid); @@ -456,7 +456,7 @@ where let mut status = rcl_action_get_zero_initialized_goal_status_array(); let ret = rcl_action_get_goal_status_array(&self.rcl_handle, &mut status); if ret != RCL_RET_OK as i32 { - println!( + log::debug!( "action server: failed to get goal status array: {}", Error::from_rcl_error(ret) ); @@ -467,7 +467,7 @@ where &status as *const _ as *const std::os::raw::c_void, ); if ret != RCL_RET_OK as i32 { - println!( + log::debug!( "action server: failed to publish status: {}", Error::from_rcl_error(ret) ); @@ -490,7 +490,7 @@ where rcl_action_send_result_response(&self.rcl_handle, &mut req, msg.void_ptr_mut()) }; if ret != RCL_RET_OK as i32 { - println!( + log::debug!( "action server: could send result request response. {}", Error::from_rcl_error(ret) ); @@ -551,7 +551,7 @@ where }; if ret != RCL_RET_OK as i32 { - println!( + log::debug!( "action server: could send result request response. {}", Error::from_rcl_error(ret) ); @@ -624,7 +624,7 @@ where }; if ret != RCL_RET_OK as i32 { - eprintln!("coult not publish {}", Error::from_rcl_error(ret)); + log::error!("could not publish {}", Error::from_rcl_error(ret)); } Ok(()) // todo: error codes } @@ -651,7 +651,7 @@ where unsafe { rcl_action_server_goal_exists(action_server.handle(), &*goal_info_native) }; if !goal_exists { - println!("tried to publish result without a goal"); + log::debug!("tried to publish result without a goal"); return Err(Error::RCL_RET_ACTION_GOAL_HANDLE_INVALID); } diff --git a/r2r/src/clients.rs b/r2r/src/clients.rs index 9ff2ade13..7bea2eb24 100644 --- a/r2r/src/clients.rs +++ b/r2r/src/clients.rs @@ -100,7 +100,7 @@ where // instead of "canceled" we return invalid client. Ok(receiver.map_err(|_| Error::RCL_RET_CLIENT_INVALID)) } else { - eprintln!("coult not send request {}", result); + log::error!("could not send request {}", result); Err(Error::from_rcl_error(result)) } } @@ -127,7 +127,7 @@ impl UntypedClient_ { // instead of "canceled" we return invalid client. Ok(receiver.map_err(|_| Error::RCL_RET_CLIENT_INVALID)) } else { - eprintln!("coult not send request {}", result); + log::error!("could not send request {}", result); Err(Error::from_rcl_error(result)) } } @@ -181,7 +181,7 @@ where match sender.send(response) { Ok(()) => {} Err(e) => { - println!("error sending to client: {:?}", e); + log::debug!("error sending to client: {:?}", e); } } } else { @@ -191,7 +191,7 @@ where .map(|(id, _)| id.to_string()) .collect::>() .join(","); - eprintln!( + log::error!( "no such req id: {}, we have [{}], ignoring", request_id.sequence_number, we_have ); @@ -267,7 +267,7 @@ impl Client_ for UntypedClient_ { match sender.send(response) { Ok(()) => {} Err(e) => { - println!("error sending to client: {:?}", e); + log::debug!("error sending to client: {:?}", e); } } } else { @@ -277,7 +277,7 @@ impl Client_ for UntypedClient_ { .map(|(id, _)| id.to_string()) .collect::>() .join(","); - eprintln!( + log::error!( "no such req id: {}, we have [{}], ignoring", request_id.sequence_number, we_have ); diff --git a/r2r/src/clocks.rs b/r2r/src/clocks.rs index 9ca7cb549..993e1646e 100644 --- a/r2r/src/clocks.rs +++ b/r2r/src/clocks.rs @@ -43,7 +43,7 @@ impl Clock { ) }; if ret != RCL_RET_OK as i32 { - eprintln!("could not create {:?} clock: {}", ct, ret); + log::error!("could not create {:?} clock: {}", ct, ret); return Err(Error::from_rcl_error(ret)); } @@ -60,7 +60,7 @@ impl Clock { let ret = unsafe { rcl_clock_get_now(&mut *self.clock_handle, &mut tp) }; if ret != RCL_RET_OK as i32 { - eprintln!("could not create steady clock: {}", ret); + log::error!("could not create steady clock: {}", ret); return Err(Error::from_rcl_error(ret)); } diff --git a/r2r/src/lib.rs b/r2r/src/lib.rs index 0c63a2b34..708368b48 100644 --- a/r2r/src/lib.rs +++ b/r2r/src/lib.rs @@ -44,7 +44,7 @@ //! // Run the subscriber in one task, printing the messages //! spawner.spawn_local(async move { //! subscriber.for_each(|msg| { -//! println!("got new msg: {}", msg.data); +//! log::debug!("got new msg: {}", msg.data); //! future::ready(()) //! }).await //! })?; diff --git a/r2r/src/msg_types.rs b/r2r/src/msg_types.rs index f057e792e..559aeb3e0 100644 --- a/r2r/src/msg_types.rs +++ b/r2r/src/msg_types.rs @@ -463,7 +463,7 @@ mod tests { let x = rosidl_typesupport_introspection_c__get_message_type_support_handle__std_msgs__msg__String(); let members = (*x).data as *const rosidl_typesupport_introspection_c__MessageMembers; - println!("{:#?}", *members); + log::debug!("{:#?}", *members); assert_eq!((*members).member_count_, 1); @@ -476,7 +476,7 @@ mod tests { assert_eq!(s, "String"); let member = (*members).members_; - println!("member: {:#?}", *member); + log::debug!("member: {:#?}", *member); let field_name = CStr::from_ptr((*member).name_).to_str().unwrap(); let type_id = (*member).type_id_; let is_array = (*member).is_array_; @@ -492,17 +492,17 @@ mod tests { unsafe { let x = rosidl_typesupport_introspection_c__get_message_type_support_handle__geometry_msgs__msg__AccelWithCovariance(); let members = (*x).data as *const rosidl_typesupport_introspection_c__MessageMembers; - println!("{:#?}", *members); + log::debug!("{:#?}", *members); let memberslice = std::slice::from_raw_parts((*members).members_, (*members).member_count_ as usize); for member in memberslice { - println!("member: {:#?}", *member); + log::debug!("member: {:#?}", *member); } let msg_native = WrappedNativeMsg::::new(); let mut msg = geometry_msgs::msg::AccelWithCovariance::from_native(&msg_native); - println!("{:#?}", msg); + log::debug!("{:#?}", msg); msg.covariance[0] = 10.0; msg.covariance[10] = 10.0; msg.covariance[35] = 99.0; @@ -510,7 +510,7 @@ mod tests { let msg_native2 = WrappedNativeMsg::::from(&msg); let msg2 = geometry_msgs::msg::AccelWithCovariance::from_native(&msg_native2); - println!("{:#?}", msg2); + log::debug!("{:#?}", msg2); } } @@ -521,17 +521,17 @@ mod tests { unsafe { let x = rosidl_typesupport_introspection_c__get_message_type_support_handle__shape_msgs__msg__SolidPrimitive(); let members = (*x).data as *const rosidl_typesupport_introspection_c__MessageMembers; - println!("{:#?}", *members); + log::debug!("{:#?}", *members); let memberslice = std::slice::from_raw_parts((*members).members_, (*members).member_count_ as usize); for member in memberslice { - println!("member: {:#?}", *member); + log::debug!("member: {:#?}", *member); } let msg_native = WrappedNativeMsg::::new(); let mut msg = shape_msgs::msg::SolidPrimitive::from_native(&msg_native); - println!("{:#?}", msg); + log::debug!("{:#?}", msg); msg.dimensions.push(1.0); msg.dimensions.push(1.0); msg.dimensions.push(1.0); @@ -566,7 +566,7 @@ mod tests { msg.positions.push(34.0); let new_native = WrappedNativeMsg::::from(&msg); let new_msg = JointTrajectoryPoint::from_native(&new_native); - println!("{:#?}", new_msg); + log::debug!("{:#?}", new_msg); assert_eq!(msg, new_msg); } @@ -579,7 +579,7 @@ mod tests { let mut new_native = WrappedNativeMsg::::from(&msg); unsafe { *new_native.positions.data = 88.9 }; let new_msg = JointTrajectoryPoint::from_native(&new_native); - println!("{:#?}", new_msg); + log::debug!("{:#?}", new_msg); assert_ne!(msg, new_msg); } @@ -649,7 +649,7 @@ mod tests { #[test] fn test_test_msgs_array() { let mut msg = test_msgs::msg::Arrays::default(); - println!("msg: {:?}", msg.string_values); + log::debug!("msg: {:?}", msg.string_values); msg.string_values = vec!["hej".to_string(), "hopp".to_string(), "stropp".to_string()]; let msg_native = WrappedNativeMsg::::from(&msg); @@ -663,7 +663,7 @@ mod tests { #[should_panic] fn test_test_msgs_array_too_few_elems() { let mut msg = test_msgs::msg::Arrays::default(); - println!("msg: {:?}", msg.string_values); + log::debug!("msg: {:?}", msg.string_values); msg.string_values = vec!["hej".to_string(), "hopp".to_string()]; let _msg_native = WrappedNativeMsg::::from(&msg); } @@ -675,7 +675,7 @@ mod tests { let rust_str = "ハローワールド"; msg.wstring_value = rust_str.to_string(); let native = WrappedNativeMsg::::from(&msg); - println!("msg: {:?}", msg); + log::debug!("msg: {:?}", msg); let msg2 = test_msgs::msg::WStrings::from_native(&native); assert_eq!(msg.wstring_value, msg2.wstring_value); } @@ -690,7 +690,7 @@ mod tests { }; let rn = WrappedNativeMsg::<_>::from(&req); let req2 = AddTwoInts::Request::from_native(&rn); - println!("req2 {:?}", req2); + log::debug!("req2 {:?}", req2); assert_eq!(req, req2); let resp = AddTwoInts::Response { @@ -699,7 +699,7 @@ mod tests { }; let rn = WrappedNativeMsg::<_>::from(&resp); let resp2 = AddTwoInts::Response::from_native(&rn); - println!("resp {:?}", resp2); + log::debug!("resp {:?}", resp2); assert_eq!(resp, resp2); } @@ -709,8 +709,8 @@ mod tests { use std_srvs::srv::Empty; let req = Empty::Request::default(); let resp = Empty::Response::default(); - println!("req {:?}", req); - println!("resp {:?}", resp); + log::debug!("req {:?}", req); + log::debug!("resp {:?}", resp); } #[cfg(r2r__example_interfaces__action__Fibonacci)] @@ -720,7 +720,7 @@ mod tests { let goal = Fibonacci::Goal { order: 5 }; let gn = WrappedNativeMsg::<_>::from(&goal); let goal2 = Fibonacci::Goal::from_native(&gn); - println!("goal2 {:?}", goal2); + log::debug!("goal2 {:?}", goal2); assert_eq!(goal, goal2); let res = Fibonacci::Result { @@ -728,7 +728,7 @@ mod tests { }; let rn = WrappedNativeMsg::<_>::from(&res); let res2 = Fibonacci::Result::from_native(&rn); - println!("res2 {:?}", res2); + log::debug!("res2 {:?}", res2); assert_eq!(res, res2); let fb = Fibonacci::Feedback { @@ -736,7 +736,7 @@ mod tests { }; let fbn = WrappedNativeMsg::<_>::from(&fb); let fb2 = Fibonacci::Feedback::from_native(&fbn); - println!("feedback2 {:?}", fb2); + log::debug!("feedback2 {:?}", fb2); assert_eq!(fb, fb2); let fb = WrappedNativeMsg::::new(); diff --git a/r2r/src/nodes.rs b/r2r/src/nodes.rs index 9d4e0208b..bc26f4b6b 100644 --- a/r2r/src/nodes.rs +++ b/r2r/src/nodes.rs @@ -94,7 +94,7 @@ impl Node { let ret = unsafe { rcl_arguments_get_param_overrides(&ctx.global_arguments, params.as_mut()) }; if ret != RCL_RET_OK as i32 { - eprintln!("could not read parameters: {}", ret); + log::error!("could not read parameters: {}", ret); return Err(Error::from_rcl_error(ret)); } @@ -192,7 +192,7 @@ impl Node { node.load_params()?; Ok(node) } else { - eprintln!("could not create node{}", res); + log::error!("could not create node{}", res); Err(Error::from_rcl_error(res)) } } @@ -242,7 +242,7 @@ impl Node { // if the value changed, send out new value on parameter event stream if changed { if let Err(e) = event_tx.try_send((p.name.clone(), val)) { - println!("Warning: could not send parameter event ({}).", e); + log::debug!("Warning: could not send parameter event ({}).", e); } } } @@ -528,7 +528,7 @@ impl Node { ) }; if ret != RCL_RET_OK as i32 { - eprintln!("could not create steady clock: {}", ret); + log::error!("could not create steady clock: {}", ret); return Err(Error::from_rcl_error(ret)); } let mut clock_handle = Box::new(unsafe { clock_handle.assume_init() }); @@ -925,7 +925,7 @@ impl Node { ) }; if ret != RCL_RET_OK as i32 { - eprintln!("could not get topic names and types {}", ret); + log::error!("could not get topic names and types {}", ret); return Err(Error::from_rcl_error(ret)); } @@ -971,7 +971,7 @@ impl Node { }; if ret != RCL_RET_OK as i32 { - eprintln!("could not create timer: {}", ret); + log::error!("could not create timer: {}", ret); return Err(Error::from_rcl_error(ret)); } @@ -1023,7 +1023,7 @@ impl Timer_ { return true; } if e.is_full() { - println!( + log::debug!( "Warning: timer tick not handled in time - no wakeup will occur" ); } diff --git a/r2r/src/parameters.rs b/r2r/src/parameters.rs index 0402b8fee..4ea1b10d4 100644 --- a/r2r/src/parameters.rs +++ b/r2r/src/parameters.rs @@ -90,7 +90,7 @@ impl ParameterValue { 8 => ParameterValue::DoubleArray(msg.double_array_value), 9 => ParameterValue::StringArray(msg.string_array_value), _ => { - println!("warning: malformed parametervalue message"); + log::debug!("warning: malformed parametervalue message"); ParameterValue::NotSet } } diff --git a/r2r/src/publishers.rs b/r2r/src/publishers.rs index 2c0f0b9e9..a860e21e3 100644 --- a/r2r/src/publishers.rs +++ b/r2r/src/publishers.rs @@ -128,7 +128,7 @@ impl PublisherUntyped { if result == RCL_RET_OK as i32 { Ok(()) } else { - eprintln!("coult not publish {}", result); + log::error!("could not publish {}", result); Err(Error::from_rcl_error(result)) } } @@ -160,7 +160,7 @@ where if result == RCL_RET_OK as i32 { Ok(()) } else { - eprintln!("coult not publish {}", result); + log::error!("could not publish {}", result); Err(Error::from_rcl_error(result)) } } @@ -182,7 +182,7 @@ where }; if ret != RCL_RET_OK as i32 { // TODO: Switch to logging library - eprintln!("Failed getting loaned message"); + log::error!("Failed getting loaned message"); return Err(Error::from_rcl_error(ret)) } @@ -208,11 +208,11 @@ where Ok(msg) } else { static LOG_LOANED_ERROR: Once = Once::new(); - LOG_LOANED_ERROR.call_once(|| { + LOG_LOANED_ERROR.call_once(|| { // TODO: Switch to logging library - eprintln!("Currently used middleware can't loan messages. Local allocator will be used."); + log::error!("Currently used middleware can't loan messages. Local allocator will be used."); }); - + Ok(WrappedNativeMsg::::new()) } } @@ -250,7 +250,7 @@ where if result == RCL_RET_OK as i32 { Ok(()) } else { - eprintln!("could not publish native {}", result); + log::error!("could not publish native {}", result); Err(Error::from_rcl_error(result)) } } diff --git a/r2r/src/services.rs b/r2r/src/services.rs index f3c4068b2..79529a23d 100644 --- a/r2r/src/services.rs +++ b/r2r/src/services.rs @@ -104,7 +104,7 @@ where if e.is_disconnected() { return true; } - eprintln!("warning: could not send service request ({})", e) + log::error!("warning: could not send service request ({})", e) } } // TODO handle failure. false diff --git a/r2r/src/subscribers.rs b/r2r/src/subscribers.rs index d672063c1..4184ea0b8 100644 --- a/r2r/src/subscribers.rs +++ b/r2r/src/subscribers.rs @@ -63,7 +63,7 @@ where // user dropped the handle to the stream, signal removal. return true; } - println!("error {:?}", e) + log::debug!("error {:?}", e) } } false @@ -140,7 +140,7 @@ where // user dropped the handle to the stream, signal removal. return true; } - eprintln!("error {:?}", e) + log::error!("error {:?}", e) } false } @@ -176,7 +176,7 @@ impl Subscriber_ for UntypedSubscriber { // user dropped the handle to the stream, signal removal. return true; } - println!("error {:?}", e) + log::debug!("error {:?}", e) } } false diff --git a/r2r/src/utils.rs b/r2r/src/utils.rs index 9f738e807..ca7c13906 100644 --- a/r2r/src/utils.rs +++ b/r2r/src/utils.rs @@ -20,7 +20,7 @@ pub fn log(msg: &str, logger_name: &str, file: &str, line: u32, severity: LogSev if !is_init { let ret = unsafe { rcutils_logging_initialize() }; if ret != RCL_RET_OK as i32 { - eprintln!("could not create logging system (Err: {})", ret); + log::error!("could not create logging system (Err: {})", ret); return; } } From e23f6ee88118edd33d6eadb5dc0e0e605aa8f79d Mon Sep 17 00:00:00 2001 From: Jiangeng Dong Date: Sat, 10 Jun 2023 13:35:41 -0700 Subject: [PATCH 2/3] wip: revert the println in mod test --- r2r/src/lib.rs | 2 +- r2r/src/msg_types.rs | 42 +++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/r2r/src/lib.rs b/r2r/src/lib.rs index 708368b48..0c63a2b34 100644 --- a/r2r/src/lib.rs +++ b/r2r/src/lib.rs @@ -44,7 +44,7 @@ //! // Run the subscriber in one task, printing the messages //! spawner.spawn_local(async move { //! subscriber.for_each(|msg| { -//! log::debug!("got new msg: {}", msg.data); +//! println!("got new msg: {}", msg.data); //! future::ready(()) //! }).await //! })?; diff --git a/r2r/src/msg_types.rs b/r2r/src/msg_types.rs index 559aeb3e0..f057e792e 100644 --- a/r2r/src/msg_types.rs +++ b/r2r/src/msg_types.rs @@ -463,7 +463,7 @@ mod tests { let x = rosidl_typesupport_introspection_c__get_message_type_support_handle__std_msgs__msg__String(); let members = (*x).data as *const rosidl_typesupport_introspection_c__MessageMembers; - log::debug!("{:#?}", *members); + println!("{:#?}", *members); assert_eq!((*members).member_count_, 1); @@ -476,7 +476,7 @@ mod tests { assert_eq!(s, "String"); let member = (*members).members_; - log::debug!("member: {:#?}", *member); + println!("member: {:#?}", *member); let field_name = CStr::from_ptr((*member).name_).to_str().unwrap(); let type_id = (*member).type_id_; let is_array = (*member).is_array_; @@ -492,17 +492,17 @@ mod tests { unsafe { let x = rosidl_typesupport_introspection_c__get_message_type_support_handle__geometry_msgs__msg__AccelWithCovariance(); let members = (*x).data as *const rosidl_typesupport_introspection_c__MessageMembers; - log::debug!("{:#?}", *members); + println!("{:#?}", *members); let memberslice = std::slice::from_raw_parts((*members).members_, (*members).member_count_ as usize); for member in memberslice { - log::debug!("member: {:#?}", *member); + println!("member: {:#?}", *member); } let msg_native = WrappedNativeMsg::::new(); let mut msg = geometry_msgs::msg::AccelWithCovariance::from_native(&msg_native); - log::debug!("{:#?}", msg); + println!("{:#?}", msg); msg.covariance[0] = 10.0; msg.covariance[10] = 10.0; msg.covariance[35] = 99.0; @@ -510,7 +510,7 @@ mod tests { let msg_native2 = WrappedNativeMsg::::from(&msg); let msg2 = geometry_msgs::msg::AccelWithCovariance::from_native(&msg_native2); - log::debug!("{:#?}", msg2); + println!("{:#?}", msg2); } } @@ -521,17 +521,17 @@ mod tests { unsafe { let x = rosidl_typesupport_introspection_c__get_message_type_support_handle__shape_msgs__msg__SolidPrimitive(); let members = (*x).data as *const rosidl_typesupport_introspection_c__MessageMembers; - log::debug!("{:#?}", *members); + println!("{:#?}", *members); let memberslice = std::slice::from_raw_parts((*members).members_, (*members).member_count_ as usize); for member in memberslice { - log::debug!("member: {:#?}", *member); + println!("member: {:#?}", *member); } let msg_native = WrappedNativeMsg::::new(); let mut msg = shape_msgs::msg::SolidPrimitive::from_native(&msg_native); - log::debug!("{:#?}", msg); + println!("{:#?}", msg); msg.dimensions.push(1.0); msg.dimensions.push(1.0); msg.dimensions.push(1.0); @@ -566,7 +566,7 @@ mod tests { msg.positions.push(34.0); let new_native = WrappedNativeMsg::::from(&msg); let new_msg = JointTrajectoryPoint::from_native(&new_native); - log::debug!("{:#?}", new_msg); + println!("{:#?}", new_msg); assert_eq!(msg, new_msg); } @@ -579,7 +579,7 @@ mod tests { let mut new_native = WrappedNativeMsg::::from(&msg); unsafe { *new_native.positions.data = 88.9 }; let new_msg = JointTrajectoryPoint::from_native(&new_native); - log::debug!("{:#?}", new_msg); + println!("{:#?}", new_msg); assert_ne!(msg, new_msg); } @@ -649,7 +649,7 @@ mod tests { #[test] fn test_test_msgs_array() { let mut msg = test_msgs::msg::Arrays::default(); - log::debug!("msg: {:?}", msg.string_values); + println!("msg: {:?}", msg.string_values); msg.string_values = vec!["hej".to_string(), "hopp".to_string(), "stropp".to_string()]; let msg_native = WrappedNativeMsg::::from(&msg); @@ -663,7 +663,7 @@ mod tests { #[should_panic] fn test_test_msgs_array_too_few_elems() { let mut msg = test_msgs::msg::Arrays::default(); - log::debug!("msg: {:?}", msg.string_values); + println!("msg: {:?}", msg.string_values); msg.string_values = vec!["hej".to_string(), "hopp".to_string()]; let _msg_native = WrappedNativeMsg::::from(&msg); } @@ -675,7 +675,7 @@ mod tests { let rust_str = "ハローワールド"; msg.wstring_value = rust_str.to_string(); let native = WrappedNativeMsg::::from(&msg); - log::debug!("msg: {:?}", msg); + println!("msg: {:?}", msg); let msg2 = test_msgs::msg::WStrings::from_native(&native); assert_eq!(msg.wstring_value, msg2.wstring_value); } @@ -690,7 +690,7 @@ mod tests { }; let rn = WrappedNativeMsg::<_>::from(&req); let req2 = AddTwoInts::Request::from_native(&rn); - log::debug!("req2 {:?}", req2); + println!("req2 {:?}", req2); assert_eq!(req, req2); let resp = AddTwoInts::Response { @@ -699,7 +699,7 @@ mod tests { }; let rn = WrappedNativeMsg::<_>::from(&resp); let resp2 = AddTwoInts::Response::from_native(&rn); - log::debug!("resp {:?}", resp2); + println!("resp {:?}", resp2); assert_eq!(resp, resp2); } @@ -709,8 +709,8 @@ mod tests { use std_srvs::srv::Empty; let req = Empty::Request::default(); let resp = Empty::Response::default(); - log::debug!("req {:?}", req); - log::debug!("resp {:?}", resp); + println!("req {:?}", req); + println!("resp {:?}", resp); } #[cfg(r2r__example_interfaces__action__Fibonacci)] @@ -720,7 +720,7 @@ mod tests { let goal = Fibonacci::Goal { order: 5 }; let gn = WrappedNativeMsg::<_>::from(&goal); let goal2 = Fibonacci::Goal::from_native(&gn); - log::debug!("goal2 {:?}", goal2); + println!("goal2 {:?}", goal2); assert_eq!(goal, goal2); let res = Fibonacci::Result { @@ -728,7 +728,7 @@ mod tests { }; let rn = WrappedNativeMsg::<_>::from(&res); let res2 = Fibonacci::Result::from_native(&rn); - log::debug!("res2 {:?}", res2); + println!("res2 {:?}", res2); assert_eq!(res, res2); let fb = Fibonacci::Feedback { @@ -736,7 +736,7 @@ mod tests { }; let fbn = WrappedNativeMsg::<_>::from(&fb); let fb2 = Fibonacci::Feedback::from_native(&fbn); - log::debug!("feedback2 {:?}", fb2); + println!("feedback2 {:?}", fb2); assert_eq!(fb, fb2); let fb = WrappedNativeMsg::::new(); From aad057a949e54e76953f245f883e5d29e060b7a1 Mon Sep 17 00:00:00 2001 From: Jiangeng Dong Date: Sun, 25 Jun 2023 10:54:45 -0700 Subject: [PATCH 3/3] wip: increase version --- r2r/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r2r/Cargo.toml b/r2r/Cargo.toml index b474f800e..49ca8de59 100644 --- a/r2r/Cargo.toml +++ b/r2r/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "r2r" -version = "0.7.3" +version = "0.7.4" authors = ["Martin Dahl "] description = "Easy to use, runtime-agnostic, async rust bindings for ROS2." license = "MIT AND Apache-2.0"