Skip to content

Commit

Permalink
Changed udp logging config to have an own udp receiving configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen committed Dec 6, 2024
1 parent c4f4cd7 commit e0729f6
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 20 deletions.
17 changes: 13 additions & 4 deletions ecal/core/include/ecal/config/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
7 changes: 3 additions & 4 deletions ecal/core/src/config/builder/logging_attribute_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
18 changes: 16 additions & 2 deletions ecal/core/src/config/configuration_to_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,22 +584,36 @@ namespace YAML
/____/\___/\_, /\_, /_/_//_/\_, /
/___//___/ /___/
*/

Node convert<eCAL::Logging::Sinks::UDPReceiver::Configuration>::encode(const eCAL::Logging::Sinks::UDPReceiver::Configuration& config_)
{
Node node;
node["enable"] = config_.enable;
node["port"] = config_.port;
return node;
}

bool convert<eCAL::Logging::Sinks::UDPReceiver::Configuration>::decode(const Node& node_, eCAL::Logging::Sinks::UDPReceiver::Configuration& config_)
{
AssignValue<bool>(config_.enable, node_, "enable");
AssignValue<unsigned int>(config_.port, node_, "port");

return true;
}

Node convert<eCAL::Logging::Sinks::UDP::Configuration>::encode(const eCAL::Logging::Sinks::UDP::Configuration& config_)
{
Node node;
node["enable"] = config_.enable;
node["port"] = config_.port;
node["level"] = LogLevelToVector(config_.filter_log_udp);
node["receive"] = config_.receive;
return node;
}

bool convert<eCAL::Logging::Sinks::UDP::Configuration>::decode(const Node& node_, eCAL::Logging::Sinks::UDP::Configuration& config_)
{
AssignValue<bool>(config_.enable, node_, "enable");
AssignValue<unsigned int>(config_.port, node_, "port");
AssignValue<bool>(config_.receive, node_, "receive");

std::vector<std::string> tmp;
AssignValue<std::vector<std::string>>(tmp, node_, "level");
Expand Down
8 changes: 8 additions & 0 deletions ecal/core/src/config/configuration_to_yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ namespace YAML
/____/\___/\_, /\_, /_/_//_/\_, /
/___//___/ /___/
*/
template<>
struct convert<eCAL::Logging::Sinks::UDPReceiver::Configuration>
{
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<eCAL::Logging::Sinks::UDP::Configuration>
{
Expand Down
7 changes: 5 additions & 2 deletions ecal/core/src/config/default_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ namespace eCAL
SUDPReceiver udp_receiver;

bool network_enabled;
bool udp_enabled;
bool receive_enabled;
std::string host_name;
};
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/logging/ecal_log_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
36 changes: 30 additions & 6 deletions ecal/tests/cpp/logging_test/src/logging_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit e0729f6

Please sign in to comment.