Skip to content

Commit

Permalink
Reworked logging structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen committed Dec 6, 2024
1 parent 9ceee76 commit 76707d5
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 124 deletions.
36 changes: 21 additions & 15 deletions ecal/core/include/ecal/config/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace eCAL
{
namespace Logging
{
namespace Sinks
namespace Provider
{
struct Sink
{
Expand All @@ -57,21 +57,9 @@ namespace eCAL

namespace UDP
{
struct ReceiverConfiguration
{
bool enable { false }; //!< Enable UDP receiver (Default: false)
unsigned int port { 14001 }; //!< UDP port number (Default: 14001)
};

struct ProviderConfiguration
{
unsigned int port { 14001 }; //!< UDP port number (Default: 14001)
};

struct Configuration
{
ReceiverConfiguration receiver;
ProviderConfiguration provider;
unsigned int port { 14001 }; //!< UDP port number (Default: 14001)
};
}

Expand All @@ -86,10 +74,28 @@ namespace eCAL

};
}

namespace Receiver
{
namespace UDP
{
struct Configuration
{
unsigned int port { 14001 }; //!< UDP port number (Default: 14001)
};
}

struct Configuration
{
bool enable { false }; //!< Enable UDP receiver (Default: false)
UDP::Configuration udp_config;
};
}

struct Configuration
{
Sinks::Configuration sinks;
Provider::Configuration provider;
Receiver::Configuration receiver;
};
}
}
12 changes: 6 additions & 6 deletions ecal/core/include/ecal/ecal_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ namespace eCAL
{
namespace Init
{
static const unsigned int Publisher = 0x001;
static const unsigned int Subscriber = 0x002;
static const unsigned int Service = 0x004;
static const unsigned int Monitoring = 0x008;
static const unsigned int Logging = 0x010;
static const unsigned int TimeSync = 0x020;
static const unsigned int Publisher = 0x001;
static const unsigned int Subscriber = 0x002;
static const unsigned int Service = 0x004;
static const unsigned int Monitoring = 0x008;
static const unsigned int Logging = 0x010;
static const unsigned int TimeSync = 0x020;

static const unsigned int All = Publisher
| Subscriber
Expand Down
20 changes: 10 additions & 10 deletions ecal/core/src/config/builder/logging_attribute_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ namespace eCAL
attributes.unit_name = Process::GetUnitName();
attributes.level = log_level_info;

attributes.udp_sink.enabled = log_config_.sinks.udp.enable;
attributes.udp_sink.filter_log = log_config_.sinks.udp.filter_log;
attributes.udp_sink.enabled = log_config_.provider.udp.enable;
attributes.udp_sink.filter_log = log_config_.provider.udp.filter_log;

attributes.file_sink.enabled = log_config_.sinks.file.enable;
attributes.file_sink.filter_log = log_config_.sinks.file.filter_log;
attributes.file_config.path = log_config_.sinks.file_config.path;
attributes.file_sink.enabled = log_config_.provider.file.enable;
attributes.file_sink.filter_log = log_config_.provider.file.filter_log;
attributes.file_config.path = log_config_.provider.file_config.path;
if (attributes.file_config.path.empty())
{
// check ECAL_DATA
// Creates path if not exists
attributes.file_config.path = Util::GeteCALLogPath();
}

attributes.console_sink.enabled = log_config_.sinks.console.enable;
attributes.console_sink.filter_log = log_config_.sinks.console.filter_log;
attributes.console_sink.enabled = log_config_.provider.console.enable;
attributes.console_sink.filter_log = log_config_.provider.console.filter_log;

// UDP related configuration part
attributes.udp_config.broadcast = !reg_config_.network_enabled;
attributes.udp_config.loopback = reg_config_.loopback;

attributes.udp_config.sndbuf = tl_config_.udp.send_buffer;
attributes.udp_config.port = log_config_.sinks.udp_config.provider.port;
attributes.udp_config.port = log_config_.provider.udp_config.port;

switch (tl_config_.udp.mode)
{
Expand All @@ -63,13 +63,13 @@ namespace eCAL
attributes.network_enabled = reg_config_.network_enabled;
attributes.host_name = Process::GetHostName();

attributes.receive_enabled = log_config_.sinks.udp_config.receiver.enable;
attributes.receive_enabled = log_config_.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 = log_config_.sinks.udp_config.receiver.port;
attributes.udp_receiver.port = log_config_.receiver.udp_config.port;

switch (tl_config_.udp.mode)
{
Expand Down
64 changes: 32 additions & 32 deletions ecal/core/src/config/configuration_to_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,60 +577,56 @@ namespace YAML
/___//___/ /___/
*/

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

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

return true;
}

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

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

AssignValue<bool>(config_.enable, node_, "enable");
AssignValue<eCAL::Logging::Receiver::UDP::Configuration>(config_.udp_config, node_, "udp_config");
return true;
}

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

bool convert<eCAL::Logging::Sinks::UDP::Configuration>::decode(const Node& node_, eCAL::Logging::Sinks::UDP::Configuration& config_)
bool convert<eCAL::Logging::Provider::UDP::Configuration>::decode(const Node& node_, eCAL::Logging::Provider::UDP::Configuration& config_)
{
AssignValue<eCAL::Logging::Sinks::UDP::ProviderConfiguration>(config_.provider, node_, "provider");
AssignValue<eCAL::Logging::Sinks::UDP::ReceiverConfiguration>(config_.receiver, node_, "receiver");
AssignValue<unsigned int>(config_.port, node_, "port");
return true;
}

Node convert<eCAL::Logging::Sinks::Sink>::encode(const eCAL::Logging::Sinks::Sink& config_)
Node convert<eCAL::Logging::Provider::Sink>::encode(const eCAL::Logging::Provider::Sink& config_)
{
Node node;
node["enable"] = config_.enable;
node["level"] = LogLevelToVector(config_.filter_log);
return node;
}

bool convert<eCAL::Logging::Sinks::Sink>::decode(const Node& node_, eCAL::Logging::Sinks::Sink& config_)
bool convert<eCAL::Logging::Provider::Sink>::decode(const Node& node_, eCAL::Logging::Provider::Sink& config_)
{
AssignValue<bool>(config_.enable, node_, "enable");
std::vector<std::string> tmp;
Expand All @@ -639,48 +635,52 @@ namespace YAML
return true;
}

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

bool convert<eCAL::Logging::Sinks::File::Configuration>::decode(const Node& node_, eCAL::Logging::Sinks::File::Configuration& config_)
bool convert<eCAL::Logging::Provider::File::Configuration>::decode(const Node& node_, eCAL::Logging::Provider::File::Configuration& config_)
{
AssignValue<std::string>(config_.path, node_, "path");
return true;
}

Node convert<eCAL::Logging::Sinks::Configuration>::encode(const eCAL::Logging::Sinks::Configuration& config_)
Node convert<eCAL::Logging::Provider::Configuration>::encode(const eCAL::Logging::Provider::Configuration& config_)
{
Node node;
node["console"] = config_.console;
node["file"] = config_.file;
node["udp"] = config_.udp;
node["console"] = config_.console;
node["file"] = config_.file;
node["udp"] = config_.udp;
node["file_config"] = config_.file_config;
node["udp_config"] = config_.udp_config;
return node;
}

bool convert<eCAL::Logging::Sinks::Configuration>::decode(const Node& node_, eCAL::Logging::Sinks::Configuration& config_)
bool convert<eCAL::Logging::Provider::Configuration>::decode(const Node& node_, eCAL::Logging::Provider::Configuration& config_)
{
AssignValue<eCAL::Logging::Sinks::Sink>(config_.console, node_, "console");
AssignValue<eCAL::Logging::Sinks::Sink>(config_.file, node_, "file");
AssignValue<eCAL::Logging::Sinks::Sink>(config_.udp, node_, "udp");
AssignValue<eCAL::Logging::Sinks::UDP::Configuration>(config_.udp_config, node_, "udp");
AssignValue<eCAL::Logging::Sinks::File::Configuration>(config_.file_config, node_, "file");
AssignValue<eCAL::Logging::Provider::Sink>(config_.console, node_, "console");
AssignValue<eCAL::Logging::Provider::Sink>(config_.file, node_, "file");
AssignValue<eCAL::Logging::Provider::Sink>(config_.udp, node_, "udp");
AssignValue<eCAL::Logging::Provider::UDP::Configuration>(config_.udp_config, node_, "udp_config");
AssignValue<eCAL::Logging::Provider::File::Configuration>(config_.file_config, node_, "file_config");
return true;
}

Node convert<eCAL::Logging::Configuration>::encode(const eCAL::Logging::Configuration& config_)
{
Node node;
node["sinks"] = config_.sinks;
node["provider"] = config_.provider;
node["receiver"] = config_.receiver;
return node;
}

bool convert<eCAL::Logging::Configuration>::decode(const Node& node_, eCAL::Logging::Configuration& config_)
{
AssignValue<eCAL::Logging::Sinks::Configuration>(config_.sinks, node_, "sinks");
AssignValue<eCAL::Logging::Provider::Configuration>(config_.provider, node_, "provider");
AssignValue<eCAL::Logging::Receiver::Configuration>(config_.receiver, node_, "receiver");
return true;
}

Expand Down
36 changes: 18 additions & 18 deletions ecal/core/src/config/configuration_to_yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,51 +298,51 @@ namespace YAML
/___//___/ /___/
*/
template<>
struct convert<eCAL::Logging::Sinks::UDP::ReceiverConfiguration>
struct convert<eCAL::Logging::Receiver::UDP::Configuration>
{
static Node encode(const eCAL::Logging::Sinks::UDP::ReceiverConfiguration& config_);
static Node encode(const eCAL::Logging::Receiver::UDP::Configuration& config_);

static bool decode(const Node& node_, eCAL::Logging::Sinks::UDP::ReceiverConfiguration& config_);
static bool decode(const Node& node_, eCAL::Logging::Receiver::UDP::Configuration& config_);
};

template<>
struct convert<eCAL::Logging::Sinks::UDP::ProviderConfiguration>
struct convert<eCAL::Logging::Receiver::Configuration>
{
static Node encode(const eCAL::Logging::Sinks::UDP::ProviderConfiguration& config_);
static Node encode(const eCAL::Logging::Receiver::Configuration& config_);

static bool decode(const Node& node_, eCAL::Logging::Sinks::UDP::ProviderConfiguration& config_);
static bool decode(const Node& node_, eCAL::Logging::Receiver::Configuration& config_);
};

template<>
struct convert<eCAL::Logging::Sinks::File::Configuration>
struct convert<eCAL::Logging::Provider::File::Configuration>
{
static Node encode(const eCAL::Logging::Sinks::File::Configuration& config_);
static Node encode(const eCAL::Logging::Provider::File::Configuration& config_);

static bool decode(const Node& node_, eCAL::Logging::Sinks::File::Configuration& config_);
static bool decode(const Node& node_, eCAL::Logging::Provider::File::Configuration& config_);
};

template<>
struct convert<eCAL::Logging::Sinks::UDP::Configuration>
struct convert<eCAL::Logging::Provider::UDP::Configuration>
{
static Node encode(const eCAL::Logging::Sinks::UDP::Configuration& config_);
static Node encode(const eCAL::Logging::Provider::UDP::Configuration& config_);

static bool decode(const Node& node_, eCAL::Logging::Sinks::UDP::Configuration& config_);
static bool decode(const Node& node_, eCAL::Logging::Provider::UDP::Configuration& config_);
};

template<>
struct convert<eCAL::Logging::Sinks::Sink>
struct convert<eCAL::Logging::Provider::Sink>
{
static Node encode(const eCAL::Logging::Sinks::Sink& config_);
static Node encode(const eCAL::Logging::Provider::Sink& config_);

static bool decode(const Node& node_, eCAL::Logging::Sinks::Sink& config_);
static bool decode(const Node& node_, eCAL::Logging::Provider::Sink& config_);
};

template<>
struct convert<eCAL::Logging::Sinks::Configuration>
struct convert<eCAL::Logging::Provider::Configuration>
{
static Node encode(const eCAL::Logging::Sinks::Configuration& config_);
static Node encode(const eCAL::Logging::Provider::Configuration& config_);

static bool decode(const Node& node_, eCAL::Logging::Sinks::Configuration& config_);
static bool decode(const Node& node_, eCAL::Logging::Provider::Configuration& config_);
};

template<>
Expand Down
Loading

0 comments on commit 76707d5

Please sign in to comment.