Skip to content

Commit

Permalink
[logging] API change for ecal logging (#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peguen authored Dec 12, 2024
1 parent 8551151 commit d7a868b
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 272 deletions.
16 changes: 1 addition & 15 deletions ecal/core/include/ecal/cimpl/ecal_log_cimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,12 @@
extern "C"
{
#endif /*__cplusplus*/
/**
* @brief Sets the log level.
*
* @param level_ The level.
**/
ECALC_API void eCAL_Logging_SetLogLevel(enum eCAL_Logging_eLogLevel level_);

/**
* @brief Get the current log level.
*
* @return The current log level.
**/
ECALC_API enum eCAL_Logging_eLogLevel eCAL_Logging_GetLogLevel();

/**
* @brief Log a message (with current log level).
*
* @param msg_ The log message string.
**/
ECALC_API void eCAL_Logging_Log(const char* const msg_);
ECALC_API void eCAL_Logging_Log(enum eCAL_Logging_eLogLevel level_, const char* const msg_);

/**
* @brief Get logging string.
Expand Down
48 changes: 1 addition & 47 deletions ecal/core/include/ecal/ecal_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,59 +35,13 @@ namespace eCAL
{
namespace Logging
{
/**
* @brief Sets the log level.
*
* @param level_ The level.
**/
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.
*
* @return The current log level.
**/
ECAL_API eCAL_Logging_eLogLevel GetLogLevel();

/**
* @brief Log a message (with current log level).
*
* @param msg_ The log message string.
**/
ECAL_API void Log(const std::string& msg_);

/**
* @brief Log a message.
*
* @param level_ The level.
* @param msg_ The log message string.
**/
inline void Log(eCAL_Logging_eLogLevel level_, const std::string& msg_)
{
SetLogLevel(level_);
Log(msg_);
}
ECAL_API void Log(eCAL_Logging_eLogLevel level_, const std::string& msg_);

/**
* @brief Get logging as serialized protobuf string.
Expand Down
14 changes: 2 additions & 12 deletions ecal/core/src/cimpl/ecal_log_cimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,9 @@

extern "C"
{
ECALC_API void eCAL_Logging_SetLogLevel(enum eCAL_Logging_eLogLevel level_)
ECALC_API void eCAL_Logging_Log(enum eCAL_Logging_eLogLevel level_, const char* const msg_)
{
eCAL::Logging::SetLogLevel(level_);
}

ECALC_API enum eCAL_Logging_eLogLevel eCAL_Logging_GetLogLevel()
{
return(eCAL::Logging::GetLogLevel());
}

ECALC_API void eCAL_Logging_Log(const char* const msg_)
{
eCAL::Logging::Log(msg_);
eCAL::Logging::Log(level_, msg_);
}

ECALC_API int eCAL_Logging_GetLogging(void* buf_, int buf_len_)
Expand Down
1 change: 0 additions & 1 deletion ecal/core/src/config/builder/logging_attribute_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace eCAL
attributes.process_id = Process::GetProcessID();
attributes.process_name = Process::GetProcessName();
attributes.unit_name = Process::GetUnitName();
attributes.level = log_level_info;

attributes.udp_sink.enabled = log_config_.provider.udp.enable;
attributes.udp_sink.filter_log = log_config_.provider.udp.filter_log;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ namespace eCAL
std::string host_name;
std::string process_name;
std::string unit_name;
eCAL_Logging_eLogLevel level;
};
}
}
55 changes: 2 additions & 53 deletions ecal/core/src/logging/ecal_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,65 +32,14 @@ namespace eCAL
{
namespace Logging
{
/**
* @brief Sets the log level.
*
* @param level_ The level.
**/
void SetLogLevel(const eCAL_Logging_eLogLevel level_)
{
if(g_log_provider() != nullptr) g_log_provider()->SetLogLevel(level_);
}

/**
* @brief Sets the file log filter.
*
* @param filter_ The filter;
*/
void SetFileLogFilter(eCAL_Logging_Filter filter_)
{
if(g_log_provider() != nullptr) g_log_provider()->SetFileLogFilter(filter_);
}

/**
* @brief Sets the udp log filter.
*
* @param filter_ The filter;
*/
void SetUDPLogFilter(eCAL_Logging_Filter filter_)
{
if(g_log_provider() != nullptr) g_log_provider()->SetUDPLogFilter(filter_);
}

/**
* @brief Sets the console log filter.
*
* @param filter_ The filter;
*/
void SetConsoleLogFilter(eCAL_Logging_Filter filter_)
{
if(g_log_provider() != nullptr) g_log_provider()->SetConsoleLogFilter(filter_);
}

/**
* @brief Get the current log level.
*
* @return The current log level.
**/
eCAL_Logging_eLogLevel GetLogLevel()
{
if(g_log_provider() != nullptr) return(g_log_provider()->GetLogLevel());
else return(log_level_none);
}

/**
* @brief Log a message.
*
* @param msg_ The log message string.
**/
void Log(const std::string& msg_)
void Log(eCAL_Logging_eLogLevel level_, const std::string& msg_)
{
if(g_log_provider() != nullptr) g_log_provider()->Log(msg_);
if(g_log_provider() != nullptr) g_log_provider()->Log(level_, msg_);
}

/**
Expand Down
32 changes: 0 additions & 32 deletions ecal/core/src/logging/ecal_log_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,33 +159,6 @@ namespace eCAL
Stop();
}

void CLogProvider::SetLogLevel(const eCAL_Logging_eLogLevel level_)
{
const std::lock_guard<std::mutex> lock(m_log_mtx);
m_attributes.level = level_;
}

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

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

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

eCAL_Logging_eLogLevel CLogProvider::GetLogLevel()
{
const std::lock_guard<std::mutex> lock(m_log_mtx);
return(m_attributes.level);
}

void CLogProvider::Start()
{
// create log file if file logging is enabled
Expand Down Expand Up @@ -284,11 +257,6 @@ namespace eCAL
}
}

void CLogProvider::Log(const std::string& msg_)
{
Log(m_attributes.level, msg_);
}

void CLogProvider::Stop()
{
if(!m_created) return;
Expand Down
42 changes: 0 additions & 42 deletions ecal/core/src/logging/ecal_log_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,6 @@ namespace eCAL
**/
void Stop();

/**
* @brief Sets the log level.
*
* @param level_ The level.
**/
void SetLogLevel(eCAL_Logging_eLogLevel level_);

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

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

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

/**
* @brief Set the current log level.
*
* @return The current log level.
**/
eCAL_Logging_eLogLevel GetLogLevel();

/**
* @brief Log a message.
*
Expand All @@ -106,13 +71,6 @@ namespace eCAL
**/
void Log(eCAL_Logging_eLogLevel level_, const std::string& msg_);

/**
* @brief Log a message (with the current log level).
*
* @param msg_ The message.
**/
void Log(const std::string& msg_);

private:

CLogProvider(const CLogProvider&); // prevent copy-construction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int main(int argc, char **argv)
msgs = 0;
bytes = 0;

eCAL::Logging::Log(out.str());
eCAL::Logging::Log(log_level_info, out.str());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int main(int argc, char **argv)
out << "Messages/s: " << (unsigned int)(msgs / diff_time.count()) << std::endl;
out << "Latency (us): " << (diff_time.count() * 1e6) / (double)msgs << std::endl;
std::cout << out.str() << std::endl;
eCAL::Logging::Log(out.str());
eCAL::Logging::Log(log_level_info, out.str());

// reset counter
msgs = 0;
Expand Down
20 changes: 3 additions & 17 deletions ecal/tests/cpp/logging_test/src/logging_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ TEST(logging_levels /*unused*/, all /*unused*/)
eCAL::Finalize();
}

TEST(logging_levels /*unused*/, various /*unused*/)
TEST(logging_levels /*unused*/, log_warning_vs_info /*unused*/)
{
const std::string unit_name = "logging_levels_various_udp";
const std::string log_message = "Logging level various test for udp.";
const std::string unit_name = "logging_levels_warning_vs_info_udp";
const std::string log_message = "Logging level warning vs info test for udp.";
auto ecal_config = GetUDPConfiguration();

ecal_config.logging.provider.udp.filter_log = log_level_warning;
Expand All @@ -239,20 +239,6 @@ TEST(logging_levels /*unused*/, various /*unused*/)
eCAL::Logging::Log(log_level_warning, log_message);
EXPECT_EQ(getLogging(log), 1);

// change log filter for udp logging
eCAL::Logging::SetUDPLogFilter(log_level_info | log_level_debug1);

// logging not expected
eCAL::Logging::Log(log_level_warning, log_message);
EXPECT_EQ(getLogging(log), 0);

// logging expected
eCAL::Logging::Log(log_level_info, log_message);
EXPECT_EQ(getLogging(log), 1);

eCAL::Logging::Log(log_level_debug1, log_message);
EXPECT_EQ(getLogging(log), 1);

eCAL::Finalize();
}

Expand Down
20 changes: 1 addition & 19 deletions lang/csharp/Continental.eCAL.Core/ecal_clr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,10 @@ void Util::ShutdownProcesses()
/////////////////////////////////////////////////////////////////////////////
// Logger
/////////////////////////////////////////////////////////////////////////////
void Logger::SetLogLevel(LogLevel level_)
{
switch(level_)
{
case info:
::eCAL::Logging::SetLogLevel(log_level_info);
break;
case warning:
::eCAL::Logging::SetLogLevel(log_level_warning);
break;
case error:
::eCAL::Logging::SetLogLevel(log_level_error);
break;
case fatal:
::eCAL::Logging::SetLogLevel(log_level_fatal);
break;
}
}

void Logger::Log(System::String^ message_)
{
::eCAL::Logging::Log(StringToStlString(message_));
::eCAL::Logging::Log(log_level_all, StringToStlString(message_));
}


Expand Down
7 changes: 0 additions & 7 deletions lang/csharp/Continental.eCAL.Core/ecal_clr.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ namespace Continental
public ref class Logger
{
public:
/**
* @brief Sets the log level.
*
* @param level_ The level.
**/
static void SetLogLevel(const LogLevel level_);

/**
* @brief Log a message.
*
Expand Down
Loading

0 comments on commit d7a868b

Please sign in to comment.