From 85a55298ff167b32d75c1ed869a02ceb0e9393f0 Mon Sep 17 00:00:00 2001 From: Johannes Mey <johannes.mey@tu-dresden.de> Date: Wed, 12 May 2021 08:49:23 +0200 Subject: [PATCH] improve some debug messages --- src/MqttConnection.cpp | 14 ++++++++------ src/NngConnection.cpp | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/MqttConnection.cpp b/src/MqttConnection.cpp index f7d6b58..7c174e8 100644 --- a/src/MqttConnection.cpp +++ b/src/MqttConnection.cpp @@ -11,7 +11,7 @@ bool MqttConnection::ensureConnection() { constexpr int N_ATTEMPT = 30; if (!client.is_connected()) { - ROS_WARN_STREAM_NAMED("MqttConnection", client.get_client_id() << ": Lost connection. Reconnecting."); + ROS_WARN_STREAM("[MqttConnection] Client '" << client.get_client_id() << "' lost connection. Reconnecting."); for (int i = 0; i < N_ATTEMPT && !client.is_connected(); ++i) { try { auto rsp = client.reconnect(); @@ -20,12 +20,11 @@ bool MqttConnection::ensureConnection() { } return true; } catch (const mqtt::exception &exception) { - ROS_ERROR_STREAM_NAMED("MqttConnection", - "Problem during reconnection. Retrying in 1s. " << exception.to_string()); + ROS_ERROR_STREAM("[MqttConnection] Problem during reconnection. Retrying in 1s. Exception: " << exception.to_string()); std::this_thread::sleep_for(std::chrono::seconds(1)); } } - ROS_ERROR_STREAM_NAMED("MqttConnection", client.get_client_id() << ": Reconnection failed!"); + ROS_ERROR_STREAM("[MqttConnection] Reconnection failed for client '" << client.get_client_id() << "'."); return false; } return true; @@ -33,6 +32,8 @@ bool MqttConnection::ensureConnection() { bool MqttConnection::send(const std::string &channel, const std::string &message) { + ROS_INFO_STREAM( + "[MqttConnection] Sending message to channel " << channel << " with a length of " << message.size() << "."); if (ensureConnection()) { try { int length = message.size(); @@ -41,13 +42,14 @@ bool MqttConnection::send(const std::string &channel, const std::string &message auto pub_msg = mqtt::make_message(channel, data, length); pub_msg->set_qos(QOS); getClient().publish(pub_msg); + ROS_INFO_STREAM("[MqttConnection] Message has been sent successfully."); } catch (const mqtt::exception &exc) { - ROS_ERROR_STREAM("MqttUtil: Unable to publish message. " << exc.what()); + ROS_ERROR_STREAM("[MqttConnection] Unable to publish message. " << exc.what()); return false; } } else { - ROS_ERROR_STREAM("MqttUtil: Not connected! Unable to listen to messages."); + ROS_ERROR_STREAM("[MqttConnection] Not connected! Unable to listen to messages."); return false; } return true; diff --git a/src/NngConnection.cpp b/src/NngConnection.cpp index e30649c..e4bc1d5 100644 --- a/src/NngConnection.cpp +++ b/src/NngConnection.cpp @@ -82,7 +82,7 @@ bool NngConnection::send(const std::string &channel, const std::string &message) ROS_ERROR_STREAM("[NngConnection] nng_send returned: " << nng_strerror(rv)); return false; } else { - ROS_INFO_STREAM("[NngConnection] Scene has been sent successfully."); + ROS_INFO_STREAM("[NngConnection] Message has been sent successfully."); return true; } } -- GitLab