@@ -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+ ///
5963pub struct Context {
6064 pub ( crate ) handle : Arc < ContextHandle > ,
6165}
@@ -68,6 +72,10 @@ pub struct Context {
6872/// bindings in this library.
6973pub ( 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
7381impl 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 }
0 commit comments