From c4f4cd74b02a22609041d7f5ebaff8609e2b3474 Mon Sep 17 00:00:00 2001 From: Peguen <73380451+Peguen@users.noreply.github.com> Date: Fri, 6 Dec 2024 08:44:12 +0100 Subject: [PATCH] Better logic for logging attributes. --- .../builder/logging_attribute_builder.cpp | 34 ++++---- .../attributes/ecal_log_provider_attributes.h | 31 +++---- .../config/attributes/logging_attributes.h | 86 ------------------- .../config/builder/udp_attribute_builder.cpp | 2 +- .../config/builder/udp_attribute_builder.h | 2 +- ecal/core/src/logging/ecal_log_provider.cpp | 30 +++---- 6 files changed, 46 insertions(+), 139 deletions(-) delete mode 100644 ecal/core/src/logging/config/attributes/logging_attributes.h diff --git a/ecal/core/src/config/builder/logging_attribute_builder.cpp b/ecal/core/src/config/builder/logging_attribute_builder.cpp index 125321de39..62761eb12e 100644 --- a/ecal/core/src/config/builder/logging_attribute_builder.cpp +++ b/ecal/core/src/config/builder/logging_attribute_builder.cpp @@ -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; diff --git a/ecal/core/src/logging/config/attributes/ecal_log_provider_attributes.h b/ecal/core/src/logging/config/attributes/ecal_log_provider_attributes.h index dd0e6bc05c..18ae15651d 100644 --- a/ecal/core/src/logging/config/attributes/ecal_log_provider_attributes.h +++ b/ecal/core/src/logging/config/attributes/ecal_log_provider_attributes.h @@ -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; @@ -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; diff --git a/ecal/core/src/logging/config/attributes/logging_attributes.h b/ecal/core/src/logging/config/attributes/logging_attributes.h deleted file mode 100644 index 9105bc77c8..0000000000 --- a/ecal/core/src/logging/config/attributes/logging_attributes.h +++ /dev/null @@ -1,86 +0,0 @@ -/* ========================= eCAL LICENSE ================================= - * - * Copyright (C) 2016 - 2024 Continental Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ========================= eCAL LICENSE ================================= -*/ - -#pragma once - -#include - -#include - -namespace eCAL -{ - namespace Logging - { - struct SUDP - { - bool enabled; - unsigned int port; - 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 - { - std::string address; - int port; - int ttl; - bool broadcast; - bool loopback; - int sndbuf; - }; - - struct SUDPReceiver - { - std::string address; - int port; - bool broadcast; - bool loopback; - int rcvbuf; - }; - - struct SAttributes - { - SUDP udp; - SFile file; - SConsole console; - - SUDPSender udp_sender; - SUDPReceiver udp_receiver; - - int process_id; - bool network_enabled; - std::string host_name; - std::string process_name; - std::string unit_name; - eCAL_Logging_eLogLevel level; - }; - } -} \ No newline at end of file diff --git a/ecal/core/src/logging/config/builder/udp_attribute_builder.cpp b/ecal/core/src/logging/config/builder/udp_attribute_builder.cpp index 30eef3ed9f..f4b9b9d524 100644 --- a/ecal/core/src/logging/config/builder/udp_attribute_builder.cpp +++ b/ecal/core/src/logging/config/builder/udp_attribute_builder.cpp @@ -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; diff --git a/ecal/core/src/logging/config/builder/udp_attribute_builder.h b/ecal/core/src/logging/config/builder/udp_attribute_builder.h index afa0f9ef62..8e9ce6d6fa 100644 --- a/ecal/core/src/logging/config/builder/udp_attribute_builder.h +++ b/ecal/core/src/logging/config/builder/udp_attribute_builder.h @@ -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_); } } diff --git a/ecal/core/src/logging/ecal_log_provider.cpp b/ecal/core/src/logging/ecal_log_provider.cpp index 230ebfaec1..d77ff160b0 100644 --- a/ecal/core/src/logging/ecal_log_provider.cpp +++ b/ecal/core/src/logging/ecal_log_provider.cpp @@ -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() @@ -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()) @@ -212,11 +212,11 @@ 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; @@ -224,7 +224,7 @@ namespace eCAL 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(attr); return m_udp_logging_sender != nullptr; @@ -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) { @@ -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;