From afe137813e93cd4c3a85524c7d2067fdd9ec6880 Mon Sep 17 00:00:00 2001 From: Yadunund Date: Tue, 2 Jul 2024 04:15:54 +0800 Subject: [PATCH] Move log_named impl to cpp Signed-off-by: Yadunund --- rmw_zenoh_cpp/src/detail/logging.cpp | 27 +++++++++++++++++++++++++++ rmw_zenoh_cpp/src/detail/logging.hpp | 23 +---------------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/rmw_zenoh_cpp/src/detail/logging.cpp b/rmw_zenoh_cpp/src/detail/logging.cpp index a54bda18..fdbb2fc8 100644 --- a/rmw_zenoh_cpp/src/detail/logging.cpp +++ b/rmw_zenoh_cpp/src/detail/logging.cpp @@ -35,4 +35,31 @@ void Logger::set_log_level(RCUTILS_LOG_SEVERITY new_level) { threshold_level_ = new_level; } + +void Logger::log_named( + RCUTILS_LOG_SEVERITY level, + const char * name, + const char * message, + ...) const +{ + if (level >= this->threshold_level_) { + rcutils_time_point_value_t now; + rcutils_ret_t ret = rcutils_system_time_now(&now); + if (ret != RCUTILS_RET_OK) { + RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to get timestamp while doing a console logging.\n"); + return; + } + static rcutils_log_location_t log_location = {__func__, __FILE__, __LINE__}; + va_list args; + va_start(args, message); + rcutils_logging_console_output_handler( + &log_location, + level, + name, + now, + message, + &args + ); + } +} } // namespace rmw_zenoh_cpp diff --git a/rmw_zenoh_cpp/src/detail/logging.hpp b/rmw_zenoh_cpp/src/detail/logging.hpp index 70cb2ab5..e81c0372 100644 --- a/rmw_zenoh_cpp/src/detail/logging.hpp +++ b/rmw_zenoh_cpp/src/detail/logging.hpp @@ -39,28 +39,7 @@ class Logger RCUTILS_LOG_SEVERITY level, const char * name, const char * message, - ...) const - { - if (level >= threshold_level_) { - rcutils_time_point_value_t now; - rcutils_ret_t ret = rcutils_system_time_now(&now); - if (ret != RCUTILS_RET_OK) { - RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to get timestamp while doing a console logging.\n"); - return; - } - static rcutils_log_location_t log_location = {__func__, __FILE__, __LINE__}; - va_list args; - va_start(args, message); - rcutils_logging_console_output_handler( - &log_location, - level, - name, - now, - message, - &args - ); - } - } + ...) const; private: RCUTILS_LOG_SEVERITY threshold_level_;