ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

ros2 logging demo C++

asked 2020-07-09 06:54:53 -0600

Almost gravatar image

updated 2020-07-09 06:55:03 -0600

I am trying to migrate code to ROS2 and I am stuck on logging.

From I got to the code example at

My problem is that all the log calls use some unscoped get_logger(), or this->get_logger in one file. But I can't find where that is defined or what it is supposed to do. ( e.g. RCLCPP_INFO(get_logger(), "Publishing: '%s'", msg->data.c_str()); )

So 1) I don't get it myself atm 2) this is not a good practice for a demo that should clarify it.

Thanks in advance for help.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-07-10 04:56:22 -0600

ahcorde gravatar image


get_logger() is part of the API of rclcpp::Node see the documentation.

In the example is called RCLCPP_INFO(get_logger(), ... or RCLCPP_INFO(this->get_logger(), ... because it's inside the class which extends the Node class. But if you want to use the logger outside a Node class you can use it in this way: RCLCPP_INFO(node->get_logger(), .... Or if you don't have an available node you can called it: `RCLCPP_ERROR(rclcpp::get_logger("string of the logger", ... )

edit flag offensive delete link more


Perfect answer, thank you. I think it would really be worth clarifying in the tutorial.

Almost gravatar image Almost  ( 2020-07-11 06:40:28 -0600 )edit

Question Tools

1 follower


Asked: 2020-07-09 06:54:53 -0600

Seen: 4,809 times

Last updated: Jul 10 '20