Skip to content

Commit

Permalink
Switch to using RCLCPP logging macros in the lifecycle package. (#644)
Browse files Browse the repository at this point in the history
* Switch to using RCLCPP logging macros in the lifecycle package.

This ensures that the logging will go out to rosout and
to disk (if configured like that).

Signed-off-by: Chris Lalancette <clalancette@gmail.com>
  • Loading branch information
clalancette committed Jul 19, 2023
1 parent 766f3e2 commit 019b64d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 27 deletions.
1 change: 0 additions & 1 deletion demo_nodes_cpp/src/topics/talker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Talker : public rclcpp::Node
msg_ = std::make_unique<std_msgs::msg::String>();
msg_->data = "Hello World: " + std::to_string(count_++);
RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", msg_->data.c_str());
RCUTILS_LOG_INFO("RCUTILS_LOG_INFO: publishing");
// Put the message into a queue to be processed by the middleware.
// This call is non-blocking.
pub_->publish(std::move(msg_));
Expand Down
6 changes: 3 additions & 3 deletions lifecycle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ add_executable(lifecycle_talker
src/lifecycle_talker.cpp)
ament_target_dependencies(lifecycle_talker
"lifecycle_msgs"
"rclcpp"
"rclcpp_lifecycle"
"std_msgs"
)
add_executable(lifecycle_listener
src/lifecycle_listener.cpp)
ament_target_dependencies(lifecycle_listener
"lifecycle_msgs"
"rclcpp_lifecycle"
"rclcpp"
"std_msgs"
)
add_executable(lifecycle_service_client
src/lifecycle_service_client.cpp)
ament_target_dependencies(lifecycle_service_client
"lifecycle_msgs"
"rclcpp_lifecycle"
"std_msgs"
"rclcpp"
)

install(TARGETS
Expand Down
11 changes: 4 additions & 7 deletions lifecycle/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>lifecycle_msgs</build_depend>
<build_depend>rclcpp_lifecycle</build_depend>
<build_depend>std_msgs</build_depend>

<exec_depend>rclcpp_lifecycle</exec_depend>
<exec_depend>lifecycle_msgs</exec_depend>
<exec_depend>std_msgs</exec_depend>
<depend>lifecycle_msgs</depend>
<depend>rclcpp</depend>
<depend>rclcpp_lifecycle</depend>
<depend>std_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
3 changes: 1 addition & 2 deletions lifecycle/src/lifecycle_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <functional>
#include <memory>
#include <string>

#include "lifecycle_msgs/msg/transition_event.hpp"

#include "rclcpp/rclcpp.hpp"

#include "rcutils/logging_macros.h"

#include "std_msgs/msg/string.hpp"

/// LifecycleListener class as a simple listener node
Expand Down
3 changes: 1 addition & 2 deletions lifecycle/src/lifecycle_service_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <chrono>
#include <future>
#include <memory>
#include <string>
#include <thread>
Expand All @@ -24,8 +25,6 @@

#include "rclcpp/rclcpp.hpp"

#include "rcutils/logging_macros.h"

using namespace std::chrono_literals;

// which node to handle
Expand Down
16 changes: 4 additions & 12 deletions lifecycle/src/lifecycle_talker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

#include <chrono>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
Expand All @@ -27,8 +26,6 @@
#include "rclcpp_lifecycle/lifecycle_node.hpp"
#include "rclcpp_lifecycle/lifecycle_publisher.hpp"

#include "rcutils/logging_macros.h"

#include "std_msgs/msg/string.hpp"

using namespace std::chrono_literals;
Expand Down Expand Up @@ -83,11 +80,9 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
if (!pub_->is_activated()) {
RCLCPP_INFO(
get_logger(), "Lifecycle publisher is currently inactive. Messages are not published.");
RCUTILS_LOG_INFO("RCUTILS_LOG_INFO: inactive");
} else {
RCLCPP_INFO(
get_logger(), "Lifecycle publisher is active. Publishing: [%s]", msg->data.c_str());
RCUTILS_LOG_INFO("RCUTILS_LOG_INFO: publishing");
}

// We independently from the current state call publish on the lifecycle
Expand Down Expand Up @@ -154,7 +149,7 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
// Overriding this method is optional, a lot of times the default is enough.
LifecycleNode::on_activate(state);

RCUTILS_LOG_INFO_NAMED(get_name(), "on_activate() is called.");
RCLCPP_INFO(get_logger(), "on_activate() is called.");

// Let's sleep for 2 seconds.
// We emulate we are doing important
Expand Down Expand Up @@ -190,7 +185,7 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
// Overriding this method is optional, a lot of times the default is enough.
LifecycleNode::on_deactivate(state);

RCUTILS_LOG_INFO_NAMED(get_name(), "on_deactivate() is called.");
RCLCPP_INFO(get_logger(), "on_deactivate() is called.");

// We return a success and hence invoke the transition to the next
// step: "inactive".
Expand Down Expand Up @@ -221,7 +216,7 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
timer_.reset();
pub_.reset();

RCUTILS_LOG_INFO_NAMED(get_name(), "on cleanup is called.");
RCLCPP_INFO(get_logger(), "on cleanup is called.");

// We return a success and hence invoke the transition to the next
// step: "unconfigured".
Expand Down Expand Up @@ -252,10 +247,7 @@ class LifecycleTalker : public rclcpp_lifecycle::LifecycleNode
timer_.reset();
pub_.reset();

RCUTILS_LOG_INFO_NAMED(
get_name(),
"on shutdown is called from state %s.",
state.label().c_str());
RCLCPP_INFO(get_logger(), "on shutdown is called from state %s.", state.label().c_str());

// We return a success and hence invoke the transition to the next
// step: "finalized".
Expand Down

0 comments on commit 019b64d

Please sign in to comment.