From 73af6701512578f96103e2060aa5bd6ce3ebb2d7 Mon Sep 17 00:00:00 2001 From: Yadunund Date: Tue, 2 Jul 2024 04:28:06 +0800 Subject: [PATCH] Implement rmw_set_log_severity Signed-off-by: Yadunund --- rmw_zenoh_cpp/src/detail/logging_macros.hpp | 4 ++-- rmw_zenoh_cpp/src/rmw_zenoh.cpp | 22 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/logging_macros.hpp b/rmw_zenoh_cpp/src/detail/logging_macros.hpp index 89f0184c..1e6ac74f 100644 --- a/rmw_zenoh_cpp/src/detail/logging_macros.hpp +++ b/rmw_zenoh_cpp/src/detail/logging_macros.hpp @@ -23,12 +23,12 @@ // which can lead to deadlocks in rmw_zenoh especially when multiple threads // invoke GraphCache::parse_put() and GraphCache::parse_del() functions. // See https://github.com/ros2/rmw_zenoh/issues/182 for more details. -// Note: Consider adding a set_rmw_log_level() API to rmw which can override the -// default log level at the RMW layer. #define RMW_ZENOH_LOG_DEBUG_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \ RCUTILS_LOG_SEVERITY_DEBUG, __VA_ARGS__);} #define RMW_ZENOH_LOG_ERROR_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \ RCUTILS_LOG_SEVERITY_ERROR, __VA_ARGS__);} +#define RMW_ZENOH_LOG_FATAL_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \ + RCUTILS_LOG_SEVERITY_FATAL, __VA_ARGS__);} #define RMW_ZENOH_LOG_INFO_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \ RCUTILS_LOG_SEVERITY_INFO, __VA_ARGS__);} #define RMW_ZENOH_LOG_WARN_NAMED(...) {rmw_zenoh_cpp::Logger::get().log_named( \ diff --git a/rmw_zenoh_cpp/src/rmw_zenoh.cpp b/rmw_zenoh_cpp/src/rmw_zenoh.cpp index a139f191..adf61edd 100644 --- a/rmw_zenoh_cpp/src/rmw_zenoh.cpp +++ b/rmw_zenoh_cpp/src/rmw_zenoh.cpp @@ -3874,8 +3874,26 @@ rmw_service_server_is_available( rmw_ret_t rmw_set_log_severity(rmw_log_severity_t severity) { - static_cast(severity); - return RMW_RET_UNSUPPORTED; + switch (severity) { + case RMW_LOG_SEVERITY_DEBUG: + rmw_zenoh_cpp::Logger::get().set_log_level(RCUTILS_LOG_SEVERITY_DEBUG); + break; + case RMW_LOG_SEVERITY_INFO: + rmw_zenoh_cpp::Logger::get().set_log_level(RCUTILS_LOG_SEVERITY_INFO); + break; + case RMW_LOG_SEVERITY_WARN: + rmw_zenoh_cpp::Logger::get().set_log_level(RCUTILS_LOG_SEVERITY_WARN); + break; + case RMW_LOG_SEVERITY_ERROR: + rmw_zenoh_cpp::Logger::get().set_log_level(RCUTILS_LOG_SEVERITY_ERROR); + break; + case RMW_LOG_SEVERITY_FATAL: + rmw_zenoh_cpp::Logger::get().set_log_level(RCUTILS_LOG_SEVERITY_FATAL); + break; + default: + return RMW_RET_UNSUPPORTED; + } + return RMW_RET_OK; } //==============================================================================