22
33#include " agnocast/agnocast_tracepoint_wrapper.h"
44
5+ #include < rcl/error_handling.h>
6+ #include < rcl/logging.h>
7+ #include < rcutils/logging_macros.h>
8+
59namespace agnocast
610{
711
@@ -22,8 +26,19 @@ void Context::init(int argc, char const * const * argv)
2226 }
2327
2428 parsed_arguments_ = parse_arguments (args);
25- initialized_ = true ;
2629
30+ // Initialize rcl logging so that RCLCPP_INFO/WARN/etc. are written to
31+ // ~/.ros/log/ files via rcl_logging_spdlog, matching rclcpp::init() behavior.
32+ rcl_allocator_t allocator = rcl_get_default_allocator ();
33+ rcl_ret_t ret = rcl_logging_configure_with_output_handler (
34+ parsed_arguments_.get (), &allocator, rcl_logging_multiple_output_handler);
35+ if (ret != RCL_RET_OK) {
36+ RCUTILS_LOG_ERROR_NAMED (
37+ " agnocast" , " Failed to configure logging: %s" , rcl_get_error_string ().str );
38+ rcl_reset_error ();
39+ }
40+
41+ initialized_ = true ;
2742 TRACEPOINT (agnocast_init, static_cast <const void *>(this ));
2843}
2944
@@ -33,4 +48,22 @@ void init(int argc, char const * const * argv)
3348 g_context.init (argc, argv);
3449}
3550
51+ void shutdown ()
52+ {
53+ std::lock_guard<std::mutex> lock (g_context_mtx);
54+ if (!g_context.is_initialized ()) {
55+ return ;
56+ }
57+
58+ // TODO(Koichi98): Add SignalHandler cleanup (uninstall signal handlers, reset state)
59+ // and notify all executors to stop spinning via SignalHandler::notify_all_executors().
60+
61+ rcl_ret_t ret = rcl_logging_fini ();
62+ if (ret != RCL_RET_OK) {
63+ RCUTILS_LOG_ERROR_NAMED (
64+ " agnocast" , " Failed to finalize logging: %s" , rcl_get_error_string ().str );
65+ rcl_reset_error ();
66+ }
67+ }
68+
3669} // namespace agnocast
0 commit comments