Migrating from RCUTILS to RCLCPP for Enhanced /rosout Log Publishing
Opened this issue · 0 comments
h-sh-h commented
Hi
The current logging procedure uses RCUTILS, which only logs to the console and not to the /rosout topic. Similar related issue Here.
The following changes are required to migrate the logging to RCLCPP.
- Add following line to ros_compat.cpp
clcpp::Node::SharedPtr node;
- Remove RCUTILS macros from ros_compat.h and replace RCLCPP macros
// #define ROS_INFO(...) RCUTILS_LOG_INFO_NAMED(__node_name_.c_str(), __VA_ARGS__)
// #define ROS_DEBUG(...) RCUTILS_LOG_DEBUG_NAMED(__node_name_.c_str(), __VA_ARGS__)
// #define ROS_ERROR(...) RCUTILS_LOG_ERROR_NAMED(__node_name_.c_str(), __VA_ARGS__)
#define ROS_INFO(...) RCLCPP_INFO(node->get_logger(), __VA_ARGS__)
#define ROS_DEBUG(...) RCLCPP_DEBUG(node->get_logger(), __VA_ARGS__)
#define ROS_ERROR(...) RCLCPP_ERROR(node->get_logger(), __VA_ARGS__)
- Since RCLCPP needs node to get logger from, the node should be defined as extern variable in ros_compat.h
extern std::string __node_name_;
extern rclcpp::Node::SharedPtr node; // This line is added
- Modify ROS_CREATE_NODE macro in ros_compat.h (remove auto keyword)
#define ROS_CREATE_NODE(name) \
rclcpp::init(argc, argv); \
node = rclcpp::Node::make_shared(name, "/" name); \
__node_name_ = name; \
__global_clock_ = std::make_shared<rclcpp::Clock>(RCL_ROS_TIME);
After these changes, the logs are now forwarded to both console and /rosout.
Unfortunately, I don't have enough time to test the entire package after this modification to check for potential issues. Therefore, I am leaving this note here to inform others.
Thanks