Skip to content

Commit 217f42c

Browse files
geoff-imdexmxgreynwn
authored
Add rosout logging to rclrs (#422)
* Initial logging implementation * * Moved logging_fini to follow correct call sequence based on rclcpp * Primary change to fix builder's node variable going out of scope * Fix linting issue with use statement * Remove the need to Box rcl_node_t (#5) Signed-off-by: Michael X. Grey <[email protected]> * Fix linting issues * Fix logging lifecycles and clean up tests Signed-off-by: Michael X. Grey <[email protected]> * Linting fixes after logging lifecycle improvements * Introduce Logger and LogParams Signed-off-by: Michael X. Grey <[email protected]> * Cleaner logging tests Signed-off-by: Michael X. Grey <[email protected]> Signed-off-by: Michael X. Grey <[email protected]> Signed-off-by: Michael X. Grey <[email protected]> Co-authored-by: Nathan Wiebe Neufeldt <[email protected]> * Address feedback for logging PR Signed-off-by: Michael X. Grey <[email protected]> Signed-off-by: Michael X. Grey <[email protected]> Signed-off-by: Michael X. Grey <[email protected]> Co-authored-by: Nathan Wiebe Neufeldt <[email protected]> --------- Signed-off-by: Michael X. Grey <[email protected]> Signed-off-by: Michael X. Grey <[email protected]> Signed-off-by: Michael X. Grey <[email protected]> Co-authored-by: Grey <[email protected]> Co-authored-by: Nathan Wiebe Neufeldt <[email protected]>
1 parent 066dd7c commit 217f42c

13 files changed

+1479
-35
lines changed

rclrs/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fn main() {
3535
}
3636
};
3737

38+
println!("cargo:rustc-check-cfg=cfg(ros_distro, values(\"humble\", \"iron\", \"jazzy\", \"rolling\"))");
3839
println!("cargo:rustc-cfg=ros_distro=\"{ros_distro}\"");
3940

4041
let mut builder = bindgen::Builder::default()

rclrs/src/context.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
vec::Vec,
77
};
88

9-
use crate::{rcl_bindings::*, RclrsError, ToResult};
9+
use crate::{rcl_bindings::*, LoggingLifecycle, RclrsError, ToResult};
1010

1111
/// This is locked whenever initializing or dropping any middleware entity
1212
/// because we have found issues in RCL and some RMW implementations that
@@ -56,6 +56,10 @@ unsafe impl Send for rcl_context_t {}
5656
/// - middleware-specific data, e.g. the domain participant in DDS
5757
/// - the allocator used (left as the default by `rclrs`)
5858
///
59+
/// The context also configures the rcl_logging_* layer to allow publication to /rosout
60+
/// (as well as the terminal). TODO: This behaviour should be configurable using an
61+
/// "auto logging initialise" flag as per rclcpp and rclpy.
62+
///
5963
pub struct Context {
6064
pub(crate) handle: Arc<ContextHandle>,
6165
}
@@ -68,6 +72,10 @@ pub struct Context {
6872
/// bindings in this library.
6973
pub(crate) struct ContextHandle {
7074
pub(crate) rcl_context: Mutex<rcl_context_t>,
75+
/// This ensures that logging does not get cleaned up until after this ContextHandle
76+
/// has dropped.
77+
#[allow(unused)]
78+
logging: Arc<LoggingLifecycle>,
7179
}
7280

7381
impl Context {
@@ -143,9 +151,16 @@ impl Context {
143151
// Move the check after the last fini()
144152
ret?;
145153
}
154+
155+
// TODO: "Auto set-up logging" is forced but should be configurable as per rclcpp and rclpy
156+
// SAFETY: We created this context a moment ago and verified that it is valid.
157+
// No other conditions are needed.
158+
let logging = unsafe { LoggingLifecycle::configure(&rcl_context)? };
159+
146160
Ok(Self {
147161
handle: Arc::new(ContextHandle {
148162
rcl_context: Mutex::new(rcl_context),
163+
logging,
149164
}),
150165
})
151166
}

rclrs/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod clock;
1111
mod context;
1212
mod error;
1313
mod executor;
14+
mod logging;
1415
mod node;
1516
mod parameter;
1617
mod publisher;
@@ -38,6 +39,7 @@ pub use clock::*;
3839
pub use context::*;
3940
pub use error::*;
4041
pub use executor::*;
42+
pub use logging::*;
4143
pub use node::*;
4244
pub use parameter::*;
4345
pub use publisher::*;

0 commit comments

Comments
 (0)