Skip to content

Commit

Permalink
[config] Adding Attributes to logging (#1724)
Browse files Browse the repository at this point in the history
* Small cleanup in logging algorithm

* Added some output in case logfile or udp sender cannot be created

* Added some tests for logging
  • Loading branch information
Peguen authored Sep 27, 2024
1 parent 5bd95d4 commit e2aec45
Show file tree
Hide file tree
Showing 20 changed files with 962 additions and 155 deletions.
3 changes: 3 additions & 0 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ endif()
# builder
######################################
set (ecal_builder_src
src/builder/logging_attribute_builder.cpp
src/builder/monitoring_attribute_builder.cpp
src/builder/registration_attribute_builder.cpp
src/logging/builder/udp_attribute_builder.cpp
src/registration/builder/udp_shm_attribute_builder.cpp
src/registration/builder/sample_applier_attribute_builder.cpp
src/registration/udp/builder/udp_attribute_builder.cpp
Expand Down
4 changes: 2 additions & 2 deletions ecal/core/include/ecal/config/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace
{
// After switchting to c++17, this can be replaced by an inline constexpr
static const eCAL_Logging_Filter log_level_default = log_level_info | log_level_warning | log_level_error | log_level_fatal;
static const eCAL_Logging_Filter log_filter_default = log_level_info | log_level_warning | log_level_error | log_level_fatal;
}

namespace eCAL
Expand Down Expand Up @@ -68,7 +68,7 @@ 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_level_default }; //!< Log messages logged via udp network (Default: info, warning, error, fatal)
eCAL_Logging_Filter filter_log_udp { log_filter_default }; //!< Log messages logged via udp network (Default: info, warning, error, fatal)
};
}

Expand Down
19 changes: 10 additions & 9 deletions ecal/core/include/ecal/ecal_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
//@{
namespace eCAL
{
ECAL_API Configuration& GetConfiguration ();
ECAL_API Registration::Configuration& GetRegistrationConfiguration ();
ECAL_API Monitoring::Configuration& GetMonitoringConfiguration ();
ECAL_API Logging::Configuration& GetLoggingConfiguration ();
ECAL_API Subscriber::Configuration& GetSubscriberConfiguration ();
ECAL_API Publisher::Configuration& GetPublisherConfiguration ();
ECAL_API Time::Configuration& GetTimesyncConfiguration ();
ECAL_API Service::Configuration& GetServiceConfiguration ();
ECAL_API Application::Configuration& GetApplicationConfiguration ();
ECAL_API Configuration& GetConfiguration ();
ECAL_API TransportLayer::Configuration& GetTransportLayerConfiguration ();
ECAL_API Registration::Configuration& GetRegistrationConfiguration ();
ECAL_API Monitoring::Configuration& GetMonitoringConfiguration ();
ECAL_API Logging::Configuration& GetLoggingConfiguration ();
ECAL_API Subscriber::Configuration& GetSubscriberConfiguration ();
ECAL_API Publisher::Configuration& GetPublisherConfiguration ();
ECAL_API Time::Configuration& GetTimesyncConfiguration ();
ECAL_API Service::Configuration& GetServiceConfiguration ();
ECAL_API Application::Configuration& GetApplicationConfiguration ();

namespace Config
{
Expand Down
21 changes: 21 additions & 0 deletions ecal/core/include/ecal/ecal_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ namespace eCAL
**/
ECAL_API void SetLogLevel(eCAL_Logging_eLogLevel level_);

/**
* @brief Sets the file log filter.
*
* @param filter_ The filter;
*/
ECAL_API void SetFileLogFilter(eCAL_Logging_Filter filter_);

/**
* @brief Sets the udp log filter.
*
* @param filter_ The filter;
*/
ECAL_API void SetUDPLogFilter(eCAL_Logging_Filter filter_);

/**
* @brief Sets the console log filter.
*
* @param filter_ The filter;
*/
ECAL_API void SetConsoleLogFilter(eCAL_Logging_Filter filter_);

/**
* @brief Get the current log level.
*
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/include/ecal/ecal_log_level.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ enum eCAL_Logging_eLogLevel
log_level_debug4 = 128,
};

typedef char eCAL_Logging_Filter; //!< This type is to be used as a bitmask for the activated logging levels
typedef unsigned char eCAL_Logging_Filter; //!< This type is to be used as a bitmask for the activated logging levels
79 changes: 79 additions & 0 deletions ecal/core/src/builder/logging_attribute_builder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "logging_attribute_builder.h"
#include "ecal/ecal_process.h"
#include "ecal/ecal_util.h"

namespace eCAL
{
namespace Logging
{
SAttributes BuildLoggingAttributes(const Logging::Configuration& log_config_, const Registration::Configuration& reg_config_, const TransportLayer::Configuration& tl_config_)
{
SAttributes attributes;

attributes.network_enabled = reg_config_.network_enabled;
attributes.host_name = Process::GetHostName();
attributes.process_id = Process::GetProcessID();
attributes.process_name = Process::GetProcessName();
attributes.unit_name = Process::GetUnitName();
attributes.level = log_level_info;

attributes.udp.enabled = log_config_.sinks.udp.enable;
attributes.udp.port = log_config_.sinks.udp.port;
attributes.udp.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())
{
// check ECAL_DATA
// Creates path if not exists
attributes.file.path = Util::GeteCALLogPath();
}

attributes.console.enabled = log_config_.sinks.console.enable;
attributes.console.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_sender.sndbuf = tl_config_.udp.send_buffer;
attributes.udp_sender.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;
break;
case Types::UDPMode::LOCAL:
attributes.udp_sender.address = tl_config_.udp.local.group;
attributes.udp_sender.ttl = tl_config_.udp.local.ttl;
break;
default:
break;
}

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;

switch (tl_config_.udp.mode)
{
case Types::UDPMode::NETWORK:
attributes.udp_receiver.address = tl_config_.udp.network.group;
break;
case Types::UDPMode::LOCAL:
attributes.udp_receiver.address = tl_config_.udp.local.group;
break;
default:
break;
}

return attributes;
}
}
}
33 changes: 33 additions & 0 deletions ecal/core/src/builder/logging_attribute_builder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* ========================= 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 "logging/attributes/logging_attributes.h"
#include "ecal/config/logging.h"
#include "ecal/config/registration.h"
#include "ecal/config/transport_layer.h"

namespace eCAL
{
namespace Logging
{
SAttributes BuildLoggingAttributes(const Logging::Configuration& log_config_, const Registration::Configuration& reg_config_, const TransportLayer::Configuration& tl_config_);
}
}
1 change: 0 additions & 1 deletion ecal/core/src/builder/registration_attribute_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace eCAL
attr.network_enabled = reg_config_.network_enabled;
attr.loopback = reg_config_.loopback;

// TODO: Check the usage further down of host_group_name -> logic currenty missleading
if (reg_config_.host_group_name.empty())
{
attr.host_group_name = eCAL::Process::GetHostName();
Expand Down
5 changes: 5 additions & 0 deletions ecal/core/src/config/ecal_config_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ namespace eCAL
return g_ecal_configuration;
}

TransportLayer::Configuration& GetTransportLayerConfiguration()
{
return GetConfiguration().transport_layer;
}

Registration::Configuration& GetRegistrationConfiguration()
{
return GetConfiguration().registration;
Expand Down
36 changes: 18 additions & 18 deletions ecal/core/src/config/transport_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@

namespace eCAL
{
namespace TransportLayer
namespace TransportLayer
{
namespace UDP
{
namespace UDP
Configuration& Configuration::operator=(const Configuration& other)
{
Configuration& Configuration::operator=(const Configuration& other)
{
config_version = other.config_version;
join_all_interfaces = other.join_all_interfaces;
mask = other.mask;
mode = other.mode;
network = other.network;
npcap_enabled = other.npcap_enabled;
port = other.port;
receive_buffer = other.receive_buffer;
send_buffer = other.send_buffer;

return *this;
}
}
}
config_version = other.config_version;
join_all_interfaces = other.join_all_interfaces;
mask = other.mask;
mode = other.mode;
network = other.network;
npcap_enabled = other.npcap_enabled;
port = other.port;
receive_buffer = other.receive_buffer;
send_buffer = other.send_buffer;

return *this;
}
}
}
}
10 changes: 7 additions & 3 deletions ecal/core/src/ecal_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "builder/registration_attribute_builder.h"
#include "builder/monitoring_attribute_builder.h"
#include "builder/logging_attribute_builder.h"

namespace eCAL
{
Expand All @@ -52,7 +53,7 @@ namespace eCAL
bool new_initialization(false);

#if ECAL_CORE_REGISTRATION
const Registration::SAttributes registration_attr = BuildRegistrationAttributes(GetConfiguration().registration, GetConfiguration().transport_layer.udp, eCAL::Process::GetProcessID());
const Registration::SAttributes registration_attr = BuildRegistrationAttributes(GetRegistrationConfiguration(), GetTransportLayerConfiguration().udp, eCAL::Process::GetProcessID());
/////////////////////
// REGISTRATION PROVIDER
/////////////////////
Expand Down Expand Up @@ -178,7 +179,7 @@ namespace eCAL
{
if (monitoring_instance == nullptr)
{
monitoring_instance = std::make_unique<CMonitoring>(eCAL::Monitoring::BuildMonitoringAttributes(GetConfiguration().monitoring));
monitoring_instance = std::make_unique<CMonitoring>(eCAL::Monitoring::BuildMonitoringAttributes(GetMonitoringConfiguration()));
new_initialization = true;
}
}
Expand All @@ -191,7 +192,7 @@ namespace eCAL
{
if (log_instance == nullptr)
{
log_instance = std::make_unique<CLog>();
log_instance = std::make_unique<CLog>(eCAL::Logging::BuildLoggingAttributes(GetLoggingConfiguration(), GetRegistrationConfiguration(), GetTransportLayerConfiguration()));
new_initialization = true;
}
}
Expand Down Expand Up @@ -349,6 +350,9 @@ namespace eCAL
log_instance = nullptr;
initialized = false;

// reset configuration to default values
g_ecal_configuration = Configuration();

return(0);
}
}
Loading

0 comments on commit e2aec45

Please sign in to comment.