Skip to content

Commit

Permalink
Better logic for logging attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen committed Dec 6, 2024
1 parent bcf6d54 commit c4f4cd7
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 139 deletions.
34 changes: 17 additions & 17 deletions ecal/core/src/config/builder/logging_attribute_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,38 @@ namespace eCAL
attributes.unit_name = Process::GetUnitName();
attributes.level = log_level_info;

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

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

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

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

attributes.udp_sender.sndbuf = tl_config_.udp.send_buffer;
attributes.udp_sender.port = tl_config_.udp.port;
attributes.udp_config.sndbuf = tl_config_.udp.send_buffer;
attributes.udp_config.port = tl_config_.udp.port;

switch (tl_config_.udp.mode)
{
case Types::UDPMode::NETWORK:
attributes.udp_sender.address = tl_config_.udp.network.group;
attributes.udp_sender.ttl = tl_config_.udp.network.ttl;
attributes.udp_config.address = tl_config_.udp.network.group;
attributes.udp_config.ttl = tl_config_.udp.network.ttl;
break;
case Types::UDPMode::LOCAL:
attributes.udp_sender.address = tl_config_.udp.local.group;
attributes.udp_sender.ttl = tl_config_.udp.local.ttl;
attributes.udp_config.address = tl_config_.udp.local.group;
attributes.udp_config.ttl = tl_config_.udp.local.ttl;
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,13 @@ namespace eCAL
{
struct SProviderAttributes
{
struct SUDP
struct SSink
{
bool enabled;
eCAL_Logging_Filter filter_log;
};

struct SFile
{
bool enabled;
std::string path;
eCAL_Logging_Filter filter_log;
};

struct SConsole
{
bool enabled;
eCAL_Logging_Filter filter_log;
};

struct SUDPSender
struct SUDP
{
std::string address;
int port;
Expand All @@ -58,11 +45,17 @@ namespace eCAL
int sndbuf;
};

SUDP udp;
SFile file;
SConsole console;
struct SFile
{
std::string path;
};

SSink udp_sink;
SSink file_sink;
SSink console_sink;

SUDPSender udp_sender;
SUDP udp_config;
SFile file_config;

int process_id;
std::string host_name;
Expand Down
86 changes: 0 additions & 86 deletions ecal/core/src/logging/config/attributes/logging_attributes.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace eCAL
{
namespace UDP
{
eCAL::UDP::SSenderAttr ConvertToIOUDPSenderAttributes(const Logging::SProviderAttributes::SUDPSender& sender_attr_)
eCAL::UDP::SSenderAttr ConvertToIOUDPSenderAttributes(const Logging::SProviderAttributes::SUDP& sender_attr_)
{
eCAL::UDP::SSenderAttr attr;
attr.broadcast = sender_attr_.broadcast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace eCAL
{
namespace UDP
{
eCAL::UDP::SSenderAttr ConvertToIOUDPSenderAttributes (const Logging::SProviderAttributes::SUDPSender& sender_attr_);
eCAL::UDP::SSenderAttr ConvertToIOUDPSenderAttributes (const Logging::SProviderAttributes::SUDP& sender_attr_);
eCAL::UDP::SReceiverAttr ConvertToIOUDPReceiverAttributes (const Logging::SReceiverAttributes::SUDPReceiver& receiver_attr_);
}
}
Expand Down
30 changes: 15 additions & 15 deletions ecal/core/src/logging/ecal_log_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ namespace eCAL

void CLogProvider::SetFileLogFilter(eCAL_Logging_Filter filter_)
{
m_attributes.file.filter_log = filter_;
m_attributes.file_sink.filter_log = filter_;
}

void CLogProvider::SetUDPLogFilter(eCAL_Logging_Filter filter_)
{
m_attributes.udp.filter_log = filter_;
m_attributes.udp_sink.filter_log = filter_;
}

void CLogProvider::SetConsoleLogFilter(eCAL_Logging_Filter filter_)
{
m_attributes.console.filter_log = filter_;
m_attributes.console_sink.filter_log = filter_;
}

eCAL_Logging_eLogLevel CLogProvider::GetLogLevel()
Expand All @@ -189,16 +189,16 @@ namespace eCAL
void CLogProvider::Start()
{
// create log file if file logging is enabled
if (m_attributes.file.enabled)
if (m_attributes.file_sink.enabled)
{
if (!StartFileLogging())
{
logWarningToConsole("Logging for file enabled, but specified path to log is not valid or could not be created: " + m_attributes.file.path);
logWarningToConsole("Logging for file enabled, but specified path to log is not valid or could not be created: " + m_attributes.file_config.path);
}
}

// create udp logging sender if udp logging is enabled
if (m_attributes.udp.enabled)
if (m_attributes.udp_sink.enabled)
{
// create udp logging sender
if (!StartUDPLogging())
Expand All @@ -212,19 +212,19 @@ namespace eCAL

bool CLogProvider::StartFileLogging()
{
if (!isDirectoryOrCreate(m_attributes.file.path)) return false;
if (!isDirectoryOrCreate(m_attributes.file_config.path)) return false;

const std::string tstring = get_time_str();

m_logfile_name = m_attributes.file.path + tstring + "_" + m_attributes.unit_name + "_" + std::to_string(m_attributes.process_id) + ".log";
m_logfile_name = m_attributes.file_config.path + tstring + "_" + m_attributes.unit_name + "_" + std::to_string(m_attributes.process_id) + ".log";
m_logfile = fopen(m_logfile_name.c_str(), "w");

return m_logfile != nullptr;
}

bool CLogProvider::StartUDPLogging()
{
const eCAL::UDP::SSenderAttr attr = Logging::UDP::ConvertToIOUDPSenderAttributes(m_attributes.udp_sender);
const eCAL::UDP::SSenderAttr attr = Logging::UDP::ConvertToIOUDPSenderAttributes(m_attributes.udp_config);
m_udp_logging_sender = std::make_unique<eCAL::UDP::CSampleSender>(attr);

return m_udp_logging_sender != nullptr;
Expand All @@ -237,15 +237,15 @@ namespace eCAL
if(!m_created) return;
if(msg_.empty()) return;

const eCAL_Logging_Filter log_con = level_ & m_attributes.console.filter_log;
const eCAL_Logging_Filter log_file = level_ & m_attributes.file.filter_log;
const eCAL_Logging_Filter log_udp = level_ & m_attributes.udp.filter_log;
const eCAL_Logging_Filter log_con = level_ & m_attributes.console_sink.filter_log;
const eCAL_Logging_Filter log_file = level_ & m_attributes.file_sink.filter_log;
const eCAL_Logging_Filter log_udp = level_ & m_attributes.udp_sink.filter_log;
if((log_con | log_file | log_udp) == 0) return;

auto log_time = eCAL::Time::ecal_clock::now();

const bool log_to_console = m_attributes.console.enabled && log_con != 0;
const bool log_to_file = m_attributes.file.enabled && log_file != 0;
const bool log_to_console = m_attributes.console_sink.enabled && log_con != 0;
const bool log_to_file = m_attributes.file_sink.enabled && log_file != 0;

if (log_to_console || log_to_file)
{
Expand All @@ -265,7 +265,7 @@ namespace eCAL
}
}

if(m_attributes.udp.enabled && log_udp != 0 && m_udp_logging_sender)
if(m_attributes.udp_sink.enabled && log_udp != 0 && m_udp_logging_sender)
{
// set up log message
Logging::SLogMessage log_message;
Expand Down

0 comments on commit c4f4cd7

Please sign in to comment.