From e0729f6c8ad681adfb0260fd29ec25f0534e70a4 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:11:23 +0100 Subject: [PATCH] Changed udp logging config to have an own udp receiving configuration. --- ecal/core/include/ecal/config/logging.h | 17 ++++++--- .../builder/logging_attribute_builder.cpp | 7 ++-- .../core/src/config/configuration_to_yaml.cpp | 18 ++++++++-- ecal/core/src/config/configuration_to_yaml.h | 8 +++++ .../core/src/config/default_configuration.cpp | 7 ++-- .../attributes/ecal_log_receiver_attributes.h | 1 - ecal/core/src/logging/ecal_log_receiver.cpp | 2 +- .../cpp/logging_test/src/logging_test.cpp | 36 +++++++++++++++---- 8 files changed, 76 insertions(+), 20 deletions(-) diff --git a/ecal/core/include/ecal/config/logging.h b/ecal/core/include/ecal/config/logging.h index fda055e372..9abe50084b 100644 --- a/ecal/core/include/ecal/config/logging.h +++ b/ecal/core/include/ecal/config/logging.h @@ -69,15 +69,24 @@ namespace eCAL bool enable { true }; //!< Enable UDP logging (Default: false) unsigned int port { 14001 }; //!< UDP port number (Default: 14001) eCAL_Logging_Filter filter_log_udp { log_filter_default }; //!< Log messages logged via udp network (Default: info, warning, error, fatal) - bool receive { false }; //!< Enable receiving udp log messages (Default: false) + }; + } + + namespace UDPReceiver + { + struct Configuration + { + bool enable { false }; //!< Enable UDP receiver (Default: false) + unsigned int port { 14001 }; //!< UDP port number (Default: 14001) }; } struct Configuration { - Console::Configuration console; - File::Configuration file; - UDP::Configuration udp; + Console::Configuration console; + File::Configuration file; + UDP::Configuration udp; + UDPReceiver::Configuration udp_receiver; }; } diff --git a/ecal/core/src/config/builder/logging_attribute_builder.cpp b/ecal/core/src/config/builder/logging_attribute_builder.cpp index 62761eb12e..3365d97014 100644 --- a/ecal/core/src/config/builder/logging_attribute_builder.cpp +++ b/ecal/core/src/config/builder/logging_attribute_builder.cpp @@ -37,7 +37,7 @@ namespace eCAL attributes.udp_config.loopback = reg_config_.loopback; attributes.udp_config.sndbuf = tl_config_.udp.send_buffer; - attributes.udp_config.port = tl_config_.udp.port; + attributes.udp_config.port = log_config_.sinks.udp.port; switch (tl_config_.udp.mode) { @@ -63,14 +63,13 @@ namespace eCAL attributes.network_enabled = reg_config_.network_enabled; attributes.host_name = Process::GetHostName(); - attributes.udp_enabled = log_config_.sinks.udp.enable; - attributes.receive_enabled = log_config_.sinks.udp.receive; + attributes.receive_enabled = log_config_.sinks.udp_receiver.enable; attributes.udp_receiver.broadcast = !reg_config_.network_enabled; attributes.udp_receiver.loopback = true; attributes.udp_receiver.rcvbuf = tl_config_.udp.receive_buffer; - attributes.udp_receiver.port = tl_config_.udp.port; + attributes.udp_receiver.port = log_config_.sinks.udp_receiver.port; switch (tl_config_.udp.mode) { diff --git a/ecal/core/src/config/configuration_to_yaml.cpp b/ecal/core/src/config/configuration_to_yaml.cpp index f236aa7f2f..8ba6b65efd 100644 --- a/ecal/core/src/config/configuration_to_yaml.cpp +++ b/ecal/core/src/config/configuration_to_yaml.cpp @@ -584,6 +584,22 @@ namespace YAML /____/\___/\_, /\_, /_/_//_/\_, / /___//___/ /___/ */ + + Node convert::encode(const eCAL::Logging::Sinks::UDPReceiver::Configuration& config_) + { + Node node; + node["enable"] = config_.enable; + node["port"] = config_.port; + return node; + } + + bool convert::decode(const Node& node_, eCAL::Logging::Sinks::UDPReceiver::Configuration& config_) + { + AssignValue(config_.enable, node_, "enable"); + AssignValue(config_.port, node_, "port"); + + return true; + } Node convert::encode(const eCAL::Logging::Sinks::UDP::Configuration& config_) { @@ -591,7 +607,6 @@ namespace YAML node["enable"] = config_.enable; node["port"] = config_.port; node["level"] = LogLevelToVector(config_.filter_log_udp); - node["receive"] = config_.receive; return node; } @@ -599,7 +614,6 @@ namespace YAML { AssignValue(config_.enable, node_, "enable"); AssignValue(config_.port, node_, "port"); - AssignValue(config_.receive, node_, "receive"); std::vector tmp; AssignValue>(tmp, node_, "level"); diff --git a/ecal/core/src/config/configuration_to_yaml.h b/ecal/core/src/config/configuration_to_yaml.h index b983f350f8..3a3de4e125 100644 --- a/ecal/core/src/config/configuration_to_yaml.h +++ b/ecal/core/src/config/configuration_to_yaml.h @@ -297,6 +297,14 @@ namespace YAML /____/\___/\_, /\_, /_/_//_/\_, / /___//___/ /___/ */ + template<> + struct convert + { + static Node encode(const eCAL::Logging::Sinks::UDPReceiver::Configuration& config_); + + static bool decode(const Node& node_, eCAL::Logging::Sinks::UDPReceiver::Configuration& config_); + }; + template<> struct convert { diff --git a/ecal/core/src/config/default_configuration.cpp b/ecal/core/src/config/default_configuration.cpp index 946931bdd5..5f4860d356 100644 --- a/ecal/core/src/config/default_configuration.cpp +++ b/ecal/core/src/config/default_configuration.cpp @@ -338,8 +338,11 @@ namespace eCAL ss << R"( level: )" << logToArray(config_.logging.sinks.udp.filter_log_udp) << "\n"; ss << R"( # UDP Port)" << "\n"; ss << R"( port: )" << config_.logging.sinks.udp.port << "\n"; - ss << R"( # Enable receiving udp log messages)" << "\n"; - ss << R"( receive: )" << config_.logging.sinks.udp.receive << "\n"; + ss << R"( udp_receiver:)" << "\n"; + ss << R"( # Enable UDP log receiving)" << "\n"; + ss << R"( enable: )" << config_.logging.sinks.udp_receiver.enable << "\n"; + ss << R"( # UDP Port)" << "\n"; + ss << R"( port: )" << config_.logging.sinks.udp_receiver.port << "\n"; ss << R"()" << "\n"; return ss; diff --git a/ecal/core/src/logging/config/attributes/ecal_log_receiver_attributes.h b/ecal/core/src/logging/config/attributes/ecal_log_receiver_attributes.h index d65c472c73..582fedc8b1 100644 --- a/ecal/core/src/logging/config/attributes/ecal_log_receiver_attributes.h +++ b/ecal/core/src/logging/config/attributes/ecal_log_receiver_attributes.h @@ -41,7 +41,6 @@ namespace eCAL SUDPReceiver udp_receiver; bool network_enabled; - bool udp_enabled; bool receive_enabled; std::string host_name; }; diff --git a/ecal/core/src/logging/ecal_log_receiver.cpp b/ecal/core/src/logging/ecal_log_receiver.cpp index 6c58a0a585..7251bfec14 100644 --- a/ecal/core/src/logging/ecal_log_receiver.cpp +++ b/ecal/core/src/logging/ecal_log_receiver.cpp @@ -49,7 +49,7 @@ namespace eCAL void CLogReceiver::Start() { - if (m_attributes.udp_enabled && m_attributes.receive_enabled) + if (m_attributes.receive_enabled) { // set logging receive network attributes const eCAL::UDP::SReceiverAttr attr = Logging::UDP::ConvertToIOUDPReceiverAttributes(m_attributes.udp_receiver); diff --git a/ecal/tests/cpp/logging_test/src/logging_test.cpp b/ecal/tests/cpp/logging_test/src/logging_test.cpp index 8e86ff0b22..0618359542 100644 --- a/ecal/tests/cpp/logging_test/src/logging_test.cpp +++ b/ecal/tests/cpp/logging_test/src/logging_test.cpp @@ -54,11 +54,11 @@ class CoutRedirect { eCAL::Configuration GetUDPConfiguration() { eCAL::Configuration config; - config.logging.sinks.file.enable = false; - config.logging.sinks.console.enable = false; - config.logging.sinks.udp.enable = true; - config.logging.sinks.udp.receive = true; - config.logging.sinks.udp.filter_log_udp = log_level_all; + config.logging.sinks.file.enable = false; + config.logging.sinks.console.enable = false; + config.logging.sinks.udp.enable = true; + config.logging.sinks.udp_receiver.enable = true; + config.logging.sinks.udp.filter_log_udp = log_level_all; return config; } @@ -351,7 +351,7 @@ TEST(logging_disable /*unused*/, udp_receive /*unused*/) const std::string log_message = "Disabled receive logging test for udp."; auto ecal_config = GetUDPConfiguration(); - ecal_config.logging.sinks.udp.receive = false; + ecal_config.logging.sinks.udp_receiver.enable = false; eCAL::Initialize(ecal_config, unit_name.c_str(), eCAL::Init::Logging | eCAL::Init::UDPLogReceive); eCAL::Logging::Log(log_level_info, log_message); @@ -388,6 +388,30 @@ TEST(logging_disable /*unused*/, udp_no_init /*unused*/) eCAL::Finalize(); } +TEST(logging_disable /*unused*/, udp_different_receive_port /*unused*/) +{ + const std::string unit_name = "no_logging_different_udp_port"; + const std::string log_message = "No log receiving possible - different udp port."; + auto ecal_config = GetUDPConfiguration(); + + ecal_config.logging.sinks.udp_receiver.enable = true; + ecal_config.logging.sinks.udp_receiver.port = 14009; + + eCAL::Initialize(ecal_config, unit_name.c_str(), eCAL::Init::Logging | eCAL::Init::UDPLogReceive); + + eCAL::Logging::Log(log_level_info, log_message); + + std::this_thread::sleep_for(UDP_WAIT_TIME); + + eCAL::Logging::SLogging log; + eCAL::Logging::GetLogging(log); + + EXPECT_EQ(log.log_messages.size(), 0); + EXPECT_EQ(eCAL::IsInitialized(eCAL::Init::UDPLogReceive), 1); + + eCAL::Finalize(); +} + TEST(logging_disable /*unused*/, console /*unused*/) { const std::string unit_name = "logging_disable_console_test";