Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get node's logger name from rcl #433

Merged
merged 5 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rclcpp/include/rclcpp/node_interfaces/node_logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class NodeLogging : public NodeLoggingInterface
rclcpp::Logger
get_logger() const;

RCLCPP_PUBLIC
virtual
const char *
get_logger_name() const;

private:
RCLCPP_DISABLE_COPY(NodeLogging)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ class NodeLoggingInterface
virtual
rclcpp::Logger
get_logger() const = 0;

/// Return the logger name associated with the node.
/** \return The logger name associated with the node. */
RCLCPP_PUBLIC
virtual
const char *
get_logger_name() const = 0;
};

} // namespace node_interfaces
Expand Down
9 changes: 7 additions & 2 deletions rclcpp/src/rclcpp/node_interfaces/node_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ using rclcpp::node_interfaces::NodeLogging;
NodeLogging::NodeLogging(rclcpp::node_interfaces::NodeBaseInterface * node_base)
: node_base_(node_base)
{
// TODO(dhood): use the namespace (slashes converted to dots)
logger_ = rclcpp::get_logger(node_base_->get_name());
logger_ = rclcpp::get_logger(this->get_logger_name());
}

NodeLogging::~NodeLogging()
Expand All @@ -32,3 +31,9 @@ NodeLogging::get_logger() const
{
return logger_;
}

const char *
NodeLogging::get_logger_name() const
{
return rcl_node_get_logger_name(node_base_->get_rcl_node_handle());
}
15 changes: 13 additions & 2 deletions rclcpp/test/test_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,25 @@ TEST_F(TestNode, get_name_and_namespace) {
}

TEST_F(TestNode, get_logger) {
// Currently the namespace is not taken into account with the node logger name
{
auto node = std::make_shared<rclcpp::Node>("my_node");
EXPECT_STREQ("my_node", node->get_logger().get_name());
}
{
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
EXPECT_STREQ("my_node", node->get_logger().get_name());
EXPECT_STREQ("ns.my_node", node->get_logger().get_name());
}
{
auto node = std::make_shared<rclcpp::Node>("my_node", "ns");
EXPECT_STREQ("ns.my_node", node->get_logger().get_name());
}
{
auto node = std::make_shared<rclcpp::Node>("my_node", "/my/ns");
EXPECT_STREQ("my.ns.my_node", node->get_logger().get_name());
}
{
auto node = std::make_shared<rclcpp::Node>("my_node", "my/ns");
EXPECT_STREQ("my.ns.my_node", node->get_logger().get_name());
}
}

Expand Down