Skip to content

Commit

Permalink
Adapt log macro
Browse files Browse the repository at this point in the history
  • Loading branch information
bha-evs committed Aug 8, 2024
1 parent df6214a commit a539261
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 49 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ include(cmake/fetch_content.cmake)
# in code coverage computation as they are test programs themselves.
set(EXTRA_COVERAGE_EXCLUSION "\'${CMAKE_CURRENT_SOURCE_DIR}/integration/*\'")

project(bofstd VERSION 5.7.2.9)
project(bofstd VERSION 5.7.3.1)

if (EMSCRIPTEN)
message("Force pthread detection for BofStd compilation under EMSCRIPTEN")
Expand Down
4 changes: 2 additions & 2 deletions lib/include/bofstd/bofbasicloggerfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class BofBasicLogger : public BOF::IBofLogger
mpLogFile_X = _Append_B ? fopen(mpLogFilePath_c, "a+") : fopen(mpLogFilePath_c, "w+");
if (mpLogFile_X)
{
V_Log(LOG_SEVERITY_FORCE, __FILE__, __LINE__, __func__, "New log session started...\n");
V_Log(BOF_LOG_SEVERITY_FORCE, __FILE__, __LINE__, __func__, "New log session started...\n");
}
else
{
Expand All @@ -125,7 +125,7 @@ class BofBasicLogger : public BOF::IBofLogger

if (mpLogFile_X)
{
V_Log(LOG_SEVERITY_FORCE, __FILE__, __LINE__, __func__, "Log session finished !\n");
V_Log(BOF_LOG_SEVERITY_FORCE, __FILE__, __LINE__, __func__, "Log session finished !\n");
fclose(mpLogFile_X);
mpLogFile_X = nullptr;
}
Expand Down
46 changes: 23 additions & 23 deletions lib/include/bofstd/ibofloggerfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class IBofLogger
public:
enum LogSeverity : uint32_t
{
LOG_SEVERITY_FORCE = 0,
LOG_SEVERITY_ERROR,
LOG_SEVERITY_WARNING,
LOG_SEVERITY_INFO,
LOG_SEVERITY_VERBOSE,
LOG_SEVERITY_DEBUG,
LOG_SEVERITY_MAX
BOF_LOG_SEVERITY_FORCE = 0,
BOF_LOG_SEVERITY_ERROR,
BOF_LOG_SEVERITY_WARNING,
BOF_LOG_SEVERITY_INFO,
BOF_LOG_SEVERITY_VERBOSE,
BOF_LOG_SEVERITY_DEBUG,
BOF_LOG_SEVERITY_MAX
};

IBofLogger() = default;
Expand All @@ -42,7 +42,7 @@ class IBofLogger
inline bool SetLogSeverityLevel(LogSeverity _SeverityLevel_E)
{
bool Rts_B = false;
if (_SeverityLevel_E < LOG_SEVERITY_MAX)
if (_SeverityLevel_E < BOF_LOG_SEVERITY_MAX)
{
mLogSeverityLevel_E = _SeverityLevel_E;
Rts_B = true;
Expand All @@ -58,7 +58,7 @@ class IBofLogger
uint32_t mNbLogRejected_U32 = 0;

private:
LogSeverity mLogSeverityLevel_E = LogSeverity::LOG_SEVERITY_MAX;
LogSeverity mLogSeverityLevel_E = LogSeverity::BOF_LOG_SEVERITY_MAX;
};

class IBofLoggerFactory
Expand All @@ -71,7 +71,7 @@ class IBofLoggerFactory
virtual bool V_Destroy(const std::string &_rLibNamePrefix_S, const std::string &_rLoggerChannelName_S) = 0;
};

#define LOGGER_LOG(psLogger, Level, File, Line, Func, Format, ...) \
#define BOF_LOGGER_LOG(psLogger, Level, File, Line, Func, Format, ...) \
if (psLogger) \
{ \
if (Level <= psLogger->GetLogSeverityLevel()) \
Expand All @@ -85,19 +85,19 @@ class IBofLoggerFactory
} \
}

#ifdef LOGGER_FACTORY_DISABLE_LOGGING
#define LOG_FORCE(psLogger, Format, ...)
#define LOG_ERROR(psLogger, Format, ...)
#define LOG_WARNING(psLogger, Format, ...)
#define LOG_INFO(psLogger, Format, ...)
#define LOG_VERBOSE(psLogger, Format, ...)
#define LOG_DEBUG(psLogger, Format, ...)
#ifdef BOF_LOGGER_FACTORY_DISABLE_LOGGING
#define BOF_LOG_FORCE(psLogger, Format, ...)
#define BOF_LOG_ERROR(psLogger, Format, ...)
#define BOF_LOG_WARNING(psLogger, Format, ...)
#define BOF_LOG_INFO(psLogger, Format, ...)
#define BOF_LOG_VERBOSE(psLogger, Format, ...)
#define BOF_LOG_DEBUG(psLogger, Format, ...)
#else
#define LOG_FORCE(psLogger, Format, ...) LOGGER_LOG(psLogger, BOF::IBofLogger::LOG_SEVERITY_FORCE, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define LOG_ERROR(psLogger, Format, ...) LOGGER_LOG(psLogger, BOF::IBofLogger::LOG_SEVERITY_ERROR, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define LOG_WARNING(psLogger, Format, ...) LOGGER_LOG(psLogger, BOF::IBofLogger::LOG_SEVERITY_WARNING, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define LOG_INFO(psLogger, Format, ...) LOGGER_LOG(psLogger, BOF::IBofLogger::LOG_SEVERITY_INFO, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define LOG_VERBOSE(psLogger, Format, ...) LOGGER_LOG(psLogger, BOF::IBofLogger::LOG_SEVERITY_VERBOSE, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define LOG_DEBUG(psLogger, Format, ...) LOGGER_LOG(psLogger, BOF::IBofLogger::LOG_SEVERITY_DEBUG, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define BOF_LOG_FORCE(psLogger, Format, ...) BOF_LOGGER_LOG(psLogger, BOF::IBofLogger::BOF_LOG_SEVERITY_FORCE, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define BOF_LOG_ERROR(psLogger, Format, ...) BOF_LOGGER_LOG(psLogger, BOF::IBofLogger::BOF_LOG_SEVERITY_ERROR, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define BOF_LOG_WARNING(psLogger, Format, ...) BOF_LOGGER_LOG(psLogger, BOF::IBofLogger::BOF_LOG_SEVERITY_WARNING, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define BOF_LOG_INFO(psLogger, Format, ...) BOF_LOGGER_LOG(psLogger, BOF::IBofLogger::BOF_LOG_SEVERITY_INFO, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define BOF_LOG_VERBOSE(psLogger, Format, ...) BOF_LOGGER_LOG(psLogger, BOF::IBofLogger::BOF_LOG_SEVERITY_VERBOSE, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#define BOF_LOG_DEBUG(psLogger, Format, ...) BOF_LOGGER_LOG(psLogger, BOF::IBofLogger::BOF_LOG_SEVERITY_DEBUG, __FILE__, __LINE__, __func__, Format, ##__VA_ARGS__)
#endif
END_BOF_NAMESPACE()
4 changes: 2 additions & 2 deletions tests/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int main(int argc, char *argv[])

//::testing::GTEST_FLAG(filter) = "DateTime_Test.StringDateTime:SocketTcp_Test.TcpClientTest:DateTime_Test.ValidateDateTime:SocketOs_Test.SocketAddress";
// ::testing::GTEST_FLAG(filter) = "Logger_Test.*:ut_logger_ibofloggerfactory.*";
// ::testing::GTEST_FLAG(filter) = "ut_logger_ibofloggerfactory.*";
// ::testing::GTEST_FLAG(filter) = "ut_logger_ibofloggerfactory.*:Logger_Test.*";
//::testing::GTEST_FLAG(filter) = "BofThread_Test.*:Threading_Test.*";
// ::testing::GTEST_FLAG(filter) = "ut_spsc.*:ut_mpmc.*:CircularBuffer_Test.Perf";
//::testing::GTEST_FLAG(filter) = "Async_Test.OverloadCommandQueue";
Expand All @@ -138,7 +138,7 @@ int main(int argc, char *argv[])
//::testing::GTEST_FLAG(filter) = "RawCircularBuffer_Test.FillWrapOverwrite";
//::testing::GTEST_FLAG(filter) = "RawCircularBuffer_Test.*:CircularBuffer_Test.*:RawCircularBufferInSlotMode_Test.*";
//::testing::GTEST_FLAG(filter) = "BofThreadPool_Test.Dispatch";
//::testing::GTEST_FLAG(filter) = "SocketOs_Test.ListAndSetupInterface";
//::testing::GTEST_FLAG(filter) = "Api_Test.PatternCompare";
// ::testing::GTEST_FLAG(filter) = "RawCircularBufferAlwaysContiguous_Test.*:RawCircularBuffer_Test.*:RawCircularBufferInSlotMode_Test.*";
// std::string CrtDir_S;
// BOF::Bof_GetCurrentDirectory(CrtDir_S);
Expand Down
10 changes: 10 additions & 0 deletions tests/src/ut_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
#include "gtestrunner.h"
#include <bofstd/bofstd.h>
#include <bofstd/bofsystem.h>

TEST(Api_Test, Version)
{
Expand Down Expand Up @@ -56,3 +57,12 @@ TEST(Api_Test, Exception)
}
EXPECT_TRUE(ExceptionThrown_B);
}

TEST(Api_Test, PatternCompare)
{
EXPECT_TRUE(BOF::Bof_PatternCompare("abcd-osnj-hello", "abc*"));
EXPECT_TRUE(BOF::Bof_PatternCompare("abcd-osnj-hello", "*llo"));
EXPECT_FALSE(BOF::Bof_PatternCompare("abcd-osnj-hello", "*sn"));
EXPECT_FALSE(BOF::Bof_PatternCompare("abcd-osnj-hello", "sn*"));
EXPECT_FALSE(BOF::Bof_PatternCompare("abcd-osnj-hello", "*sk*"));
}
40 changes: 20 additions & 20 deletions tests/src/ut_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,12 @@ void MyLibInit(std::shared_ptr<BOF::IBofLoggerFactory> _psLoggerFactory)
}
void MyLibCode(bool _NullTestCase_B)
{
LOG_FORCE(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT], "This will be logged\n");
LOG_FORCE(S_psLoggerCollection[UT_LOGGER_CHANNEL_CODEC], "This will be logged\n");
LOG_FORCE(S_psLoggerCollection[UT_LOGGER_CHANNEL_NULLPTR], "! This will not be logged !\n");
LOG_VERBOSE(S_psLoggerCollection[UT_LOGGER_CHANNEL_DMA], "! This will not be logged !\n");
LOG_FORCE(S_psLoggerCollection[UT_LOGGER_CHANNEL_DMA], "! This one yes !\n");
LOG_INFO(S_psLoggerCollection[UT_LOGGER_CHANNEL_DMA], "! This one also !\n");
BOF_LOG_FORCE(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT], "This will be logged\n");
BOF_LOG_FORCE(S_psLoggerCollection[UT_LOGGER_CHANNEL_CODEC], "This will be logged\n");
BOF_LOG_FORCE(S_psLoggerCollection[UT_LOGGER_CHANNEL_NULLPTR], "! This will not be logged !\n");
BOF_LOG_VERBOSE(S_psLoggerCollection[UT_LOGGER_CHANNEL_DMA], "! This will not be logged !\n");
BOF_LOG_FORCE(S_psLoggerCollection[UT_LOGGER_CHANNEL_DMA], "! This one yes !\n");
BOF_LOG_INFO(S_psLoggerCollection[UT_LOGGER_CHANNEL_DMA], "! This one also !\n");
if (!_NullTestCase_B)
{
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT]->mNbLogOut_U32, 1);
Expand All @@ -590,9 +590,9 @@ void MyLibCode(bool _NullTestCase_B)
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL_DMA]->mNbLogOut_U32, 2);
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL_DMA]->mNbLogRejected_U32, 1);
}
LOG_INFO(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT], "! This will not be logged !\n");
LOG_WARNING(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT], "This will be logged\n");
LOG_ERROR(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT], "This will be logged\n");
BOF_LOG_INFO(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT], "! This will not be logged !\n");
BOF_LOG_WARNING(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT], "This will be logged\n");
BOF_LOG_ERROR(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT], "This will be logged\n");
if (!_NullTestCase_B)
{
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL_INIT]->mNbLogOut_U32, 3);
Expand All @@ -614,20 +614,20 @@ TEST(ut_logger_ibofloggerfactory, MultipleChannel)
EXPECT_TRUE(psLoggerFactory->V_Destroy("MyLib_", "DMA2"));
EXPECT_FALSE(psLoggerFactory->V_Destroy("MyLib_", "DMA3"));

EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::LOG_SEVERITY_MAX);
EXPECT_TRUE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->SetLogSeverityLevel(BOF::IBofLogger::LogSeverity::LOG_SEVERITY_WARNING));
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::LOG_SEVERITY_WARNING);
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_MAX);
EXPECT_TRUE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->SetLogSeverityLevel(BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_WARNING));
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_WARNING);

EXPECT_FALSE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->SetLogSeverityLevel(BOF::IBofLogger::LogSeverity::LOG_SEVERITY_MAX));
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::LOG_SEVERITY_WARNING);
EXPECT_FALSE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->SetLogSeverityLevel(BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_MAX));
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_WARNING);

EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_CODEC]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::LOG_SEVERITY_MAX);
EXPECT_TRUE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_CODEC]->SetLogSeverityLevel(BOF::IBofLogger::LogSeverity::LOG_SEVERITY_FORCE));
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_CODEC]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::LOG_SEVERITY_FORCE);
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_CODEC]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_MAX);
EXPECT_TRUE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_CODEC]->SetLogSeverityLevel(BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_FORCE));
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_CODEC]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_FORCE);

EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_DMA]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::LOG_SEVERITY_MAX);
EXPECT_TRUE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_DMA]->SetLogSeverityLevel(BOF::IBofLogger::LogSeverity::LOG_SEVERITY_INFO));
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_DMA]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::LOG_SEVERITY_INFO);
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_DMA]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_MAX);
EXPECT_TRUE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_DMA]->SetLogSeverityLevel(BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_INFO));
EXPECT_EQ(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_DMA]->GetLogSeverityLevel(), BOF::IBofLogger::LogSeverity::BOF_LOG_SEVERITY_INFO);

MyLibCode(false);
}
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bofstd",
"version": "5.7.2.9",
"version": "5.7.3.1",
"description": "The onbings general purpose C++ Multiplatform library",
"dependencies": [
{
Expand Down

0 comments on commit a539261

Please sign in to comment.