From a4899fb5f9333e57b2eb80854d3024d5c6778448 Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Fri, 13 Oct 2017 19:46:38 +0530 Subject: [PATCH 01/11] Fastrtps supports rich logging facilities, which could be used on any ros2 development. * To enable the same, enable setting log levels from rmw_fastrtps layers, * Add generic logging level parameters to 'rmw.h' which would be used by other layers above like rcl/rclcpp. * Hide DDS specific implementation inside rmw_fastrtps. Signed-off-by: Sriram Raghunathan --- rmw_fastrtps_cpp/CMakeLists.txt | 1 + .../src/rmw_fastrtps_configure.cpp | 31 +++++++++++++++++++ rmw_fastrtps_cpp/src/rmw_node.cpp | 2 -- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp diff --git a/rmw_fastrtps_cpp/CMakeLists.txt b/rmw_fastrtps_cpp/CMakeLists.txt index 052196fdf..140ed658b 100644 --- a/rmw_fastrtps_cpp/CMakeLists.txt +++ b/rmw_fastrtps_cpp/CMakeLists.txt @@ -61,6 +61,7 @@ add_library(rmw_fastrtps_cpp src/namespace_prefix.cpp src/qos.cpp src/rmw_init.cpp + src/rmw_fastrtps_configure.cpp src/rmw_client.cpp src/rmw_compare_gids_equal.cpp src/rmw_count.cpp diff --git a/rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp b/rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp new file mode 100644 index 000000000..9ae4291ef --- /dev/null +++ b/rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp @@ -0,0 +1,31 @@ +#include "rmw/rmw.h" + +#include "fastrtps/log/Log.h" + +extern "C" +{ +using eprosima::fastrtps::Log; + +eprosima::fastrtps::Log::Kind rmw_convert_severity_fastrtps(rmw_log_level_t level) +{ + switch(level) + { + case RMW_LOG_LEVEL_ERROR: + return Log::Kind::Error; + case RMW_LOG_LEVEL_WARNING: + return Log::Kind::Warning; + case RMW_LOG_LEVEL_INFO: + return Log::Kind::Info; + default: + //Fallback to Info if undefined types + return Log::Kind::Info; + } +} + +void +rmw_setup_fastrtps(rmw_log_level_t level) +{ + Log::Kind lvl = rmw_convert_severity_fastrtps(level); + eprosima::fastrtps::Log::SetVerbosity(lvl); +} +} diff --git a/rmw_fastrtps_cpp/src/rmw_node.cpp b/rmw_fastrtps_cpp/src/rmw_node.cpp index 3d5555434..d8ee5eeb2 100644 --- a/rmw_fastrtps_cpp/src/rmw_node.cpp +++ b/rmw_fastrtps_cpp/src/rmw_node.cpp @@ -64,8 +64,6 @@ create_node( return NULL; } - eprosima::fastrtps::Log::SetVerbosity(eprosima::fastrtps::Log::Error); - // Declare everything before beginning to create things. rmw_guard_condition_t * graph_guard_condition = nullptr; CustomParticipantInfo * node_impl = nullptr; From e1eba0fb84d5a1527cb9e5e5849c8a5e97ee19ec Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Wed, 25 Oct 2017 14:08:43 +0530 Subject: [PATCH 02/11] The changes follow the discussions https://github.com/ros2/rmw/pull/124 * The API defined is used to set the logging level particular to the DDS implementation. * This change is specific to DDS type Fast-RTPS. * The file is named as rmw_configure since we could write API's of type 'system level config setting' types here. Signed-off-by: Sriram Raghunathan --- .../src/rmw_fastrtps_configure.cpp | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp b/rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp index 9ae4291ef..19e84c631 100644 --- a/rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp +++ b/rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp @@ -1,3 +1,17 @@ +// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "rmw/rmw.h" #include "fastrtps/log/Log.h" @@ -6,26 +20,37 @@ extern "C" { using eprosima::fastrtps::Log; -eprosima::fastrtps::Log::Kind rmw_convert_severity_fastrtps(rmw_log_level_t level) +eprosima::fastrtps::Log::Kind rmw_convert_severity_type(rmw_log_severity_t severity) { - switch(level) + switch(severity) { - case RMW_LOG_LEVEL_ERROR: - return Log::Kind::Error; - case RMW_LOG_LEVEL_WARNING: + case RMW_LOG_SEVERITY_WARN: return Log::Kind::Warning; - case RMW_LOG_LEVEL_INFO: + case RMW_LOG_SEVERITY_INFO: return Log::Kind::Info; +/* Fast-RTPS supports the following logging 'Kind's. + * Error : Max priority + * Warning : Medium priority + * Info : Low priority + * From rmw logging severity there are FATAL & DEBUG types as well + * We map them to ERROR type of Fast-RTPS which has maximum priority + */ + case RMW_LOG_SEVERITY_ERROR: + case RMW_LOG_SEVERITY_FATAL: + case RMW_LOG_SEVERITY_DEBUG: + return Log::Kind::Error; default: //Fallback to Info if undefined types return Log::Kind::Info; } } -void -rmw_setup_fastrtps(rmw_log_level_t level) +rmw_ret_t +rmw_set_log_severity(rmw_log_severity_t severity) { - Log::Kind lvl = rmw_convert_severity_fastrtps(level); - eprosima::fastrtps::Log::SetVerbosity(lvl); -} + Log::Kind _severity = rmw_convert_severity_type(severity); + eprosima::fastrtps::Log::SetVerbosity(_severity); + + return RMW_RET_OK; } +} // extern "C" From 43930936fe6dbe122698c66f14f1485ef7685290 Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Wed, 25 Oct 2017 14:12:34 +0530 Subject: [PATCH 03/11] Rename file from rmw_fastrtps_configure to rmw_logging, which follows the patterns being used already. like rmw_node, rmw_publisher.. Signed-off-by: Sriram Raghunathan --- .../src/{rmw_fastrtps_configure.cpp => rmw_logging.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rmw_fastrtps_cpp/src/{rmw_fastrtps_configure.cpp => rmw_logging.cpp} (100%) diff --git a/rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp b/rmw_fastrtps_cpp/src/rmw_logging.cpp similarity index 100% rename from rmw_fastrtps_cpp/src/rmw_fastrtps_configure.cpp rename to rmw_fastrtps_cpp/src/rmw_logging.cpp From 82f178bafa282f3dce025c865684da2f80886ea1 Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Thu, 26 Oct 2017 13:39:43 +0530 Subject: [PATCH 04/11] - Fix, coding errors. - Renmae API to suite ros styles Signed-off-by: Sriram Raghunathan --- rmw_fastrtps_cpp/CMakeLists.txt | 2 +- rmw_fastrtps_cpp/src/rmw_logging.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rmw_fastrtps_cpp/CMakeLists.txt b/rmw_fastrtps_cpp/CMakeLists.txt index 140ed658b..89cfb45ec 100644 --- a/rmw_fastrtps_cpp/CMakeLists.txt +++ b/rmw_fastrtps_cpp/CMakeLists.txt @@ -61,7 +61,7 @@ add_library(rmw_fastrtps_cpp src/namespace_prefix.cpp src/qos.cpp src/rmw_init.cpp - src/rmw_fastrtps_configure.cpp + src/rmw_logging.cpp src/rmw_client.cpp src/rmw_compare_gids_equal.cpp src/rmw_count.cpp diff --git a/rmw_fastrtps_cpp/src/rmw_logging.cpp b/rmw_fastrtps_cpp/src/rmw_logging.cpp index 19e84c631..afec9e365 100644 --- a/rmw_fastrtps_cpp/src/rmw_logging.cpp +++ b/rmw_fastrtps_cpp/src/rmw_logging.cpp @@ -20,7 +20,7 @@ extern "C" { using eprosima::fastrtps::Log; -eprosima::fastrtps::Log::Kind rmw_convert_severity_type(rmw_log_severity_t severity) +eprosima::fastrtps::Log::Kind convert_rmw_severity_type(rmw_log_severity_t severity) { switch(severity) { @@ -48,7 +48,7 @@ eprosima::fastrtps::Log::Kind rmw_convert_severity_type(rmw_log_severity_t sever rmw_ret_t rmw_set_log_severity(rmw_log_severity_t severity) { - Log::Kind _severity = rmw_convert_severity_type(severity); + Log::Kind _severity = convert_rmw_severity_type(severity); eprosima::fastrtps::Log::SetVerbosity(_severity); return RMW_RET_OK; From 6c36dac53e23524cbd1d08045671ad2d0d212c78 Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Sun, 29 Oct 2017 14:22:28 +0530 Subject: [PATCH 05/11] Fix ament_cpplint warnings Signed-off-by: Sriram Raghunathan --- rmw_fastrtps_cpp/src/rmw_logging.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_logging.cpp b/rmw_fastrtps_cpp/src/rmw_logging.cpp index afec9e365..db929d4a0 100644 --- a/rmw_fastrtps_cpp/src/rmw_logging.cpp +++ b/rmw_fastrtps_cpp/src/rmw_logging.cpp @@ -40,7 +40,7 @@ eprosima::fastrtps::Log::Kind convert_rmw_severity_type(rmw_log_severity_t sever case RMW_LOG_SEVERITY_DEBUG: return Log::Kind::Error; default: - //Fallback to Info if undefined types + // Fallback to Info if undefined types return Log::Kind::Info; } } @@ -53,4 +53,4 @@ rmw_set_log_severity(rmw_log_severity_t severity) return RMW_RET_OK; } -} // extern "C" +} // extern "C" From 220b4bc3bdf4afc3335420696491bd0f6da08ea1 Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Sun, 19 Nov 2017 23:11:37 +0530 Subject: [PATCH 06/11] Remove utility function to create a 'error' returnable API for setting logging Signed-off-by: Sriram Raghunathan --- rmw_fastrtps_cpp/src/rmw_logging.cpp | 54 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_logging.cpp b/rmw_fastrtps_cpp/src/rmw_logging.cpp index db929d4a0..c37b9e620 100644 --- a/rmw_fastrtps_cpp/src/rmw_logging.cpp +++ b/rmw_fastrtps_cpp/src/rmw_logging.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include "rmw/rmw.h" +#include "rmw/error_handling.h" #include "fastrtps/log/Log.h" @@ -20,35 +21,36 @@ extern "C" { using eprosima::fastrtps::Log; -eprosima::fastrtps::Log::Kind convert_rmw_severity_type(rmw_log_severity_t severity) -{ - switch(severity) - { - case RMW_LOG_SEVERITY_WARN: - return Log::Kind::Warning; - case RMW_LOG_SEVERITY_INFO: - return Log::Kind::Info; -/* Fast-RTPS supports the following logging 'Kind's. - * Error : Max priority - * Warning : Medium priority - * Info : Low priority - * From rmw logging severity there are FATAL & DEBUG types as well - * We map them to ERROR type of Fast-RTPS which has maximum priority - */ - case RMW_LOG_SEVERITY_ERROR: - case RMW_LOG_SEVERITY_FATAL: - case RMW_LOG_SEVERITY_DEBUG: - return Log::Kind::Error; - default: - // Fallback to Info if undefined types - return Log::Kind::Info; - } -} - rmw_ret_t rmw_set_log_severity(rmw_log_severity_t severity) { - Log::Kind _severity = convert_rmw_severity_type(severity); + Log::Kind _severity; + + switch (severity) { + case RMW_LOG_SEVERITY_WARN: + _severity = Log::Kind::Warning; + break; + case RMW_LOG_SEVERITY_INFO: + _severity = Log::Kind::Info; + break; +// Fast-RTPS supports the following logging 'Kind's. +// Error : Max priority +// Warning : Medium priority +// Info : Low priority +// From rmw logging severity there is FATAL severity type we map it +// to ERROR type of Fast-RTPS which has maximum priority + case RMW_LOG_SEVERITY_DEBUG: + _severity = Log::Kind::Warning; + break; + case RMW_LOG_SEVERITY_ERROR: + case RMW_LOG_SEVERITY_FATAL: + _severity = Log::Kind::Error; + break; + default: + RMW_SET_ERROR_MSG("node handle is null"); + return RMW_RET_ERROR; + } + eprosima::fastrtps::Log::SetVerbosity(_severity); return RMW_RET_OK; From c38d5aafb2ee7bd331bcc0f27f90cb773d536997 Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Wed, 13 Dec 2017 22:06:37 +0530 Subject: [PATCH 07/11] Fix, logging msg bug. --- rmw_fastrtps_cpp/src/rmw_logging.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_fastrtps_cpp/src/rmw_logging.cpp b/rmw_fastrtps_cpp/src/rmw_logging.cpp index c37b9e620..540bfa867 100644 --- a/rmw_fastrtps_cpp/src/rmw_logging.cpp +++ b/rmw_fastrtps_cpp/src/rmw_logging.cpp @@ -47,7 +47,7 @@ rmw_set_log_severity(rmw_log_severity_t severity) _severity = Log::Kind::Error; break; default: - RMW_SET_ERROR_MSG("node handle is null"); + RMW_SET_ERROR_MSG("Unknown logging severity type, please check"); return RMW_RET_ERROR; } From 23c8b0fada0e01c0efd27c510fb0d4d097863d88 Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Tue, 19 Dec 2017 14:09:12 +0530 Subject: [PATCH 08/11] Modify logging mapping for type 'debug' from warning to info. Signed-off-by: Sriram Raghunathan --- rmw_fastrtps_cpp/src/rmw_logging.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw_fastrtps_cpp/src/rmw_logging.cpp b/rmw_fastrtps_cpp/src/rmw_logging.cpp index 540bfa867..c456f97a7 100644 --- a/rmw_fastrtps_cpp/src/rmw_logging.cpp +++ b/rmw_fastrtps_cpp/src/rmw_logging.cpp @@ -40,7 +40,7 @@ rmw_set_log_severity(rmw_log_severity_t severity) // From rmw logging severity there is FATAL severity type we map it // to ERROR type of Fast-RTPS which has maximum priority case RMW_LOG_SEVERITY_DEBUG: - _severity = Log::Kind::Warning; + _severity = Log::Kind::Info; break; case RMW_LOG_SEVERITY_ERROR: case RMW_LOG_SEVERITY_FATAL: From a01006af174b956dff2bd6d49eb5a4466eab95d9 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Tue, 19 Dec 2017 00:55:10 -0800 Subject: [PATCH 09/11] order log levels, use different local variable name, include unknown severity in error message --- rmw_fastrtps_cpp/src/rmw_logging.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_logging.cpp b/rmw_fastrtps_cpp/src/rmw_logging.cpp index c456f97a7..cfa1b739f 100644 --- a/rmw_fastrtps_cpp/src/rmw_logging.cpp +++ b/rmw_fastrtps_cpp/src/rmw_logging.cpp @@ -24,34 +24,28 @@ using eprosima::fastrtps::Log; rmw_ret_t rmw_set_log_severity(rmw_log_severity_t severity) { - Log::Kind _severity; + Log::Kind log_kind; switch (severity) { - case RMW_LOG_SEVERITY_WARN: - _severity = Log::Kind::Warning; - break; + case RMW_LOG_SEVERITY_DEBUG: + // fall through case RMW_LOG_SEVERITY_INFO: - _severity = Log::Kind::Info; + log_kind = Log::Kind::Info; break; -// Fast-RTPS supports the following logging 'Kind's. -// Error : Max priority -// Warning : Medium priority -// Info : Low priority -// From rmw logging severity there is FATAL severity type we map it -// to ERROR type of Fast-RTPS which has maximum priority - case RMW_LOG_SEVERITY_DEBUG: - _severity = Log::Kind::Info; + case RMW_LOG_SEVERITY_WARN: + log_kind = Log::Kind::Warning; break; case RMW_LOG_SEVERITY_ERROR: + // fall through case RMW_LOG_SEVERITY_FATAL: - _severity = Log::Kind::Error; + log_kind = Log::Kind::Error; break; default: - RMW_SET_ERROR_MSG("Unknown logging severity type, please check"); + RMW_SET_ERROR_MSG("Unknown logging severity type %d", severity); return RMW_RET_ERROR; } - eprosima::fastrtps::Log::SetVerbosity(_severity); + eprosima::fastrtps::Log::SetVerbosity(log_kind); return RMW_RET_OK; } From a7bd9757acdd621ea7fc69d422eb410ceea2681a Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Fri, 5 Jan 2018 20:42:18 +0530 Subject: [PATCH 10/11] Fix error due to parameterized logging --- rmw_fastrtps_cpp/src/rmw_logging.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rmw_fastrtps_cpp/src/rmw_logging.cpp b/rmw_fastrtps_cpp/src/rmw_logging.cpp index cfa1b739f..7eaa971bf 100644 --- a/rmw_fastrtps_cpp/src/rmw_logging.cpp +++ b/rmw_fastrtps_cpp/src/rmw_logging.cpp @@ -15,6 +15,8 @@ #include "rmw/rmw.h" #include "rmw/error_handling.h" +#include "rcutils/logging_macros.h" + #include "fastrtps/log/Log.h" extern "C" @@ -41,7 +43,7 @@ rmw_set_log_severity(rmw_log_severity_t severity) log_kind = Log::Kind::Error; break; default: - RMW_SET_ERROR_MSG("Unknown logging severity type %d", severity); + RCUTILS_LOG_ERROR("Unknown logging severity type %d", severity); return RMW_RET_ERROR; } From a415c52c3dcaaa9ae7ab6d49819e1264ab548b65 Mon Sep 17 00:00:00 2001 From: Sriram Raghunathan Date: Sun, 7 Jan 2018 10:45:11 +0530 Subject: [PATCH 11/11] Fix code style issues from uncrustify --- rmw_fastrtps_cpp/src/rmw_logging.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_logging.cpp b/rmw_fastrtps_cpp/src/rmw_logging.cpp index 7eaa971bf..065818a22 100644 --- a/rmw_fastrtps_cpp/src/rmw_logging.cpp +++ b/rmw_fastrtps_cpp/src/rmw_logging.cpp @@ -30,7 +30,7 @@ rmw_set_log_severity(rmw_log_severity_t severity) switch (severity) { case RMW_LOG_SEVERITY_DEBUG: - // fall through +// fall through case RMW_LOG_SEVERITY_INFO: log_kind = Log::Kind::Info; break; @@ -38,7 +38,7 @@ rmw_set_log_severity(rmw_log_severity_t severity) log_kind = Log::Kind::Warning; break; case RMW_LOG_SEVERITY_ERROR: - // fall through +// fall through case RMW_LOG_SEVERITY_FATAL: log_kind = Log::Kind::Error; break;