From 77c927ff9a2cb294a22e0fd04d16be8d1b94c2e2 Mon Sep 17 00:00:00 2001 From: Denise Eng Date: Wed, 8 Feb 2017 21:32:09 +0000 Subject: [PATCH] Add logger roscpp_internal.connections. We need more connection leve diagnostics in our logs but turning on DEBUG for roscpp_internal generates a flood of information. We only need visibility into when tcpros connections are created/dropped for publishers and subscribers. The rospy nodes currently do this but the roscpp ones do not. A DEBUG macro for logging messages to the named logger roscpp_internal.connections has been added. This will allow it to inherit the roscpp_internal log level or be turned on separately to just get connection-related messages. --- clients/roscpp/include/ros/file_log.h | 1 + clients/roscpp/src/libros/subscription.cpp | 6 +++--- clients/roscpp/src/libros/transport/transport_tcp.cpp | 6 +++--- clients/roscpp/src/libros/transport_publisher_link.cpp | 6 +++--- clients/roscpp/src/libros/transport_subscriber_link.cpp | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/clients/roscpp/include/ros/file_log.h b/clients/roscpp/include/ros/file_log.h index 933d942978..1d046d9a78 100644 --- a/clients/roscpp/include/ros/file_log.h +++ b/clients/roscpp/include/ros/file_log.h @@ -33,6 +33,7 @@ #include "common.h" #define ROSCPP_LOG_DEBUG(...) ROS_DEBUG_NAMED("roscpp_internal", __VA_ARGS__) +#define ROSCPP_CONN_LOG_DEBUG(...) ROS_DEBUG_NAMED("roscpp_internal.connections", __VA_ARGS__) namespace ros { diff --git a/clients/roscpp/src/libros/subscription.cpp b/clients/roscpp/src/libros/subscription.cpp index d2163d7d0d..e0695cc13c 100644 --- a/clients/roscpp/src/libros/subscription.cpp +++ b/clients/roscpp/src/libros/subscription.cpp @@ -503,7 +503,7 @@ void Subscription::pendingConnectionDone(const PendingConnectionPtr& conn, XmlRp } std::string pub_host = proto[1]; int pub_port = proto[2]; - ROSCPP_LOG_DEBUG("Connecting via tcpros to topic [%s] at host [%s:%d]", name_.c_str(), pub_host.c_str(), pub_port); + ROSCPP_CONN_LOG_DEBUG("Connecting via tcpros to topic [%s] at host [%s:%d]", name_.c_str(), pub_host.c_str(), pub_port); TransportTCPPtr transport(boost::make_shared(&PollManager::instance()->getPollSet())); if (transport->connect(pub_host, pub_port)) @@ -519,11 +519,11 @@ void Subscription::pendingConnectionDone(const PendingConnectionPtr& conn, XmlRp boost::mutex::scoped_lock lock(publisher_links_mutex_); addPublisherLink(pub_link); - ROSCPP_LOG_DEBUG("Connected to publisher of topic [%s] at [%s:%d]", name_.c_str(), pub_host.c_str(), pub_port); + ROSCPP_CONN_LOG_DEBUG("Connected to publisher of topic [%s] at [%s:%d]", name_.c_str(), pub_host.c_str(), pub_port); } else { - ROSCPP_LOG_DEBUG("Failed to connect to publisher of topic [%s] at [%s:%d]", name_.c_str(), pub_host.c_str(), pub_port); + ROSCPP_CONN_LOG_DEBUG("Failed to connect to publisher of topic [%s] at [%s:%d]", name_.c_str(), pub_host.c_str(), pub_port); } } else if (proto_name == "UDPROS") diff --git a/clients/roscpp/src/libros/transport/transport_tcp.cpp b/clients/roscpp/src/libros/transport/transport_tcp.cpp index f061fc2697..6417121317 100644 --- a/clients/roscpp/src/libros/transport/transport_tcp.cpp +++ b/clients/roscpp/src/libros/transport/transport_tcp.cpp @@ -315,7 +315,7 @@ bool TransportTCP::connect(const std::string& host, int port) if (((flags_ & SYNCHRONOUS) && ret != 0) || // synchronous, connect() should return 0 (!(flags_ & SYNCHRONOUS) && last_socket_error() != ROS_SOCKETS_ASYNCHRONOUS_CONNECT_RETURN)) // asynchronous, connect() should return -1 and WSAGetLastError()=WSAEWOULDBLOCK/errno=EINPROGRESS { - ROSCPP_LOG_DEBUG("Connect to tcpros publisher [%s:%d] failed with error [%d, %s]", host.c_str(), port, ret, last_socket_error_string()); + ROSCPP_CONN_LOG_DEBUG("Connect to tcpros publisher [%s:%d] failed with error [%d, %s]", host.c_str(), port, ret, last_socket_error_string()); close(); return false; @@ -340,11 +340,11 @@ bool TransportTCP::connect(const std::string& host, int port) if (flags_ & SYNCHRONOUS) { - ROSCPP_LOG_DEBUG("connect() succeeded to [%s:%d] on socket [%d]", host.c_str(), port, sock_); + ROSCPP_CONN_LOG_DEBUG("connect() succeeded to [%s:%d] on socket [%d]", host.c_str(), port, sock_); } else { - ROSCPP_LOG_DEBUG("Async connect() in progress to [%s:%d] on socket [%d]", host.c_str(), port, sock_); + ROSCPP_CONN_LOG_DEBUG("Async connect() in progress to [%s:%d] on socket [%d]", host.c_str(), port, sock_); } return true; diff --git a/clients/roscpp/src/libros/transport_publisher_link.cpp b/clients/roscpp/src/libros/transport_publisher_link.cpp index 6b28f68094..6e9b8785b4 100644 --- a/clients/roscpp/src/libros/transport_publisher_link.cpp +++ b/clients/roscpp/src/libros/transport_publisher_link.cpp @@ -223,7 +223,7 @@ void TransportPublisherLink::onRetryTimer(const ros::WallTimerEvent&) const std::string& host = old_transport->getConnectedHost(); int port = old_transport->getConnectedPort(); - ROSCPP_LOG_DEBUG("Retrying connection to [%s:%d] for topic [%s]", host.c_str(), port, topic.c_str()); + ROSCPP_CONN_LOG_DEBUG("Retrying connection to [%s:%d] for topic [%s]", host.c_str(), port, topic.c_str()); TransportTCPPtr transport(boost::make_shared(&PollManager::instance()->getPollSet())); if (transport->connect(host, port)) @@ -236,7 +236,7 @@ void TransportPublisherLink::onRetryTimer(const ros::WallTimerEvent&) } else { - ROSCPP_LOG_DEBUG("connect() failed when retrying connection to [%s:%d] for topic [%s]", host.c_str(), port, topic.c_str()); + ROSCPP_CONN_LOG_DEBUG("connect() failed when retrying connection to [%s:%d] for topic [%s]", host.c_str(), port, topic.c_str()); } } else if (parent) @@ -264,7 +264,7 @@ void TransportPublisherLink::onConnectionDropped(const ConnectionPtr& conn, Conn { std::string topic = parent ? parent->getName() : "unknown"; - ROSCPP_LOG_DEBUG("Connection to publisher [%s] to topic [%s] dropped", connection_->getTransport()->getTransportInfo().c_str(), topic.c_str()); + ROSCPP_CONN_LOG_DEBUG("Connection to publisher [%s] to topic [%s] dropped", connection_->getTransport()->getTransportInfo().c_str(), topic.c_str()); ROS_ASSERT(!needs_retry_); needs_retry_ = true; diff --git a/clients/roscpp/src/libros/transport_subscriber_link.cpp b/clients/roscpp/src/libros/transport_subscriber_link.cpp index 2257a9aefe..898b9ec262 100644 --- a/clients/roscpp/src/libros/transport_subscriber_link.cpp +++ b/clients/roscpp/src/libros/transport_subscriber_link.cpp @@ -128,7 +128,7 @@ void TransportSubscriberLink::onConnectionDropped(const ConnectionPtr& conn) if (parent) { - ROSCPP_LOG_DEBUG("Connection to subscriber [%s] to topic [%s] dropped", connection_->getRemoteString().c_str(), topic_.c_str()); + ROSCPP_CONN_LOG_DEBUG("Connection to subscriber [%s] to topic [%s] dropped", connection_->getRemoteString().c_str(), topic_.c_str()); parent->removeSubscriberLink(shared_from_this()); }