Skip to content

Commit

Permalink
Use char * in logging macros (#295)
Browse files Browse the repository at this point in the history
* Pass char * into logging macros rather than std::strings

Signed-off-by: Audrow Nash <audrow.nash@gmail.com>

* Fix logging indentation

Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
  • Loading branch information
audrow authored Dec 18, 2020
1 parent 2366967 commit 869e303
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions rclcpp/executors/multithreaded_executor/multithreaded_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class PublisherNode : public rclcpp::Node
auto curr_thread = string_thread_id();

// Prep display message
auto info_message = "\n<<THREAD " + curr_thread + ">> Publishing '%s'";
RCLCPP_INFO(this->get_logger(), info_message, message.data.c_str());
RCLCPP_INFO(
this->get_logger(), "\n<<THREAD %s>> Publishing '%s'",
curr_thread.c_str(), message.data.c_str());
this->publisher_->publish(message);
};
timer_ = this->create_wall_timer(500ms, timer_callback);
Expand Down Expand Up @@ -133,9 +134,9 @@ class DualThreadedNode : public rclcpp::Node
auto message_received_at = timing_string();

// Extract current thread
auto thread_string = "THREAD " + string_thread_id();
thread_string += " => Heard '%s' at " + message_received_at; // Prep display message
RCLCPP_INFO(this->get_logger(), thread_string, msg->data.c_str());
RCLCPP_INFO(
this->get_logger(), "THREAD %s => Heard '%s' at %s",
string_thread_id().c_str(), msg->data.c_str(), message_received_at.c_str());
}

/**
Expand All @@ -146,12 +147,10 @@ class DualThreadedNode : public rclcpp::Node
{
auto message_received_at = timing_string();

// Extract current thread
auto thread_string = "THREAD " + string_thread_id();

// Prep display message
thread_string += " => Heard '%s' at " + message_received_at;
RCLCPP_INFO(this->get_logger(), thread_string, msg->data.c_str());
RCLCPP_INFO(
this->get_logger(), "THREAD %s => Heard '%s' at %s",
string_thread_id().c_str(), msg->data.c_str(), message_received_at.c_str());
}

rclcpp::CallbackGroup::SharedPtr callback_group_subscriber1_;
Expand Down

0 comments on commit 869e303

Please sign in to comment.