Skip to content

Commit

Permalink
5.7.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bha-evs committed Jul 12, 2024
1 parent 7737d57 commit e571fbb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 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.0.3)
project(bofstd VERSION 5.7.1.4)

if (EMSCRIPTEN)
message("Force pthread detection for BofStd compilation under EMSCRIPTEN")
Expand Down
57 changes: 52 additions & 5 deletions lib/include/bofstd/bofbasicloggerfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BasicLogger : public BOF::IBofLogger
BasicLogger(const std::string &_rLibNamePrefix_S, const std::string &_rLoggerChannelName_S) : BOF::IBofLogger()
{
mChannelName_S = _rLibNamePrefix_S + _rLoggerChannelName_S;
Configure(false, "");
Open(false, false, false, "");
}
virtual ~BasicLogger()
{
Expand Down Expand Up @@ -66,42 +66,87 @@ class BasicLogger : public BOF::IBofLogger
{
fwrite(pHeader_c, strlen(pHeader_c), 1, mpLogFile_X);
fwrite(pLog_c, strlen(pLog_c), 1, mpLogFile_X);
if (mAutoFlush_B)
{
Flush();
}
}
}
}
bool Configure(bool _OutputOnScreen_B, const std::string &_rLogFileSubDir_S)
bool Open(bool _OutputOnScreen_B, bool _Append_B, bool _AutoFlush_B, const std::string &_rLogFileSubDir_S)
{
bool Rts_B = true;
char pLogFile_c[512];

mOutputOnScreen_B = _OutputOnScreen_B;
mAutoFlush_B = _AutoFlush_B;
if (_rLogFileSubDir_S.empty())
{
mpLogFile_X = nullptr;
}
else
{
sprintf(pLogFile_c, "%s/%s.log", _rLogFileSubDir_S.c_str(), mChannelName_S.c_str());
mpLogFile_X = fopen(pLogFile_c, "w+");
mpLogFile_X = _Append_B ? fopen(pLogFile_c, "w+"): fopen(pLogFile_c, "a+");
if (mpLogFile_X == nullptr)
{
V_Log(LOG_SEVERITY_FORCE, "New log session started...\n");
Rts_B = false;
}
}
return Rts_B;
}
bool Close()
{
bool Rts_B = true;

if (mpLogFile_X)
{
V_Log(LOG_SEVERITY_FORCE, "Log session finished !\n");
fclose(mpLogFile_X);
mpLogFile_X = nullptr;
}
mOutputOnScreen_B = false;

return Rts_B;
}

uint64_t Size()
{
uint64_t Rts_U64=0; //CurrentPosition_U64

if (mpLogFile_X)
{
//CurrentPosition_U64 = ftell(mpLogFile_X);
//fseek(mpLogFile_X, 0, SEEK_END);
Rts_U64 = ftell(mpLogFile_X);
//fseek(mpLogFile_X, CurrentPosition_U64, SEEK_SET);
}
return Rts_U64;
}
bool Flush()
{
bool Rts_B = true;

if (mpLogFile_X)
{
fflush(mpLogFile_X);
}
return Rts_B;
}
private:
std::string mChannelName_S;
const std::chrono::time_point<std::chrono::high_resolution_clock> mLogEpoch = std::chrono::high_resolution_clock::now();
bool mOutputOnScreen_B = false;
bool mAutoFlush_B = false;
FILE *mpLogFile_X = nullptr;
};

class BofBasicLoggerFactory : public BOF::IBofLoggerFactory
{
public:
BofBasicLoggerFactory(bool _OutputOnScreen_B, const std::string &_rLogFileSubDir_S) : mOutputOnScreen_B(_OutputOnScreen_B), mLogFileSubDir_S(_rLogFileSubDir_S)
BofBasicLoggerFactory(bool _OutputOnScreen_B, bool _Append_B, bool _AutoFlush_B, const std::string &_rLogFileSubDir_S) :
mOutputOnScreen_B(_OutputOnScreen_B), mAppend_B(_Append_B), mAutoFlush_B(_AutoFlush_B), mLogFileSubDir_S(_rLogFileSubDir_S)
{
}
virtual ~BofBasicLoggerFactory() = default;
Expand All @@ -121,7 +166,7 @@ class BofBasicLoggerFactory : public BOF::IBofLoggerFactory
psRts = std::make_shared<BasicLogger>(_rLibNamePrefix_S, _rLoggerChannelName_S);
if (psRts)
{
if (psRts->Configure(mOutputOnScreen_B, mLogFileSubDir_S))
if (psRts->Open(mOutputOnScreen_B, mAppend_B, mAutoFlush_B, mLogFileSubDir_S))
{
ChannelName_S = BuildChannelName(_rLibNamePrefix_S, _rLoggerChannelName_S);
mLoggerCollection[ChannelName_S] = psRts;
Expand Down Expand Up @@ -166,6 +211,8 @@ class BofBasicLoggerFactory : public BOF::IBofLoggerFactory
std::mutex mLoggerCollectionMtx;
std::map<std::string, std::shared_ptr<BasicLogger>> mLoggerCollection;
bool mOutputOnScreen_B;
bool mAppend_B;
bool mAutoFlush_B;
const std::string mLogFileSubDir_S;
};
END_BOF_NAMESPACE()
2 changes: 1 addition & 1 deletion tests/src/ut_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void MyLibCode(bool _NullTestCase_B)

TEST(ut_logger_ibofloggerfactory, MultipleChannel)
{
std::shared_ptr<BOF::BofBasicLoggerFactory> psLoggerFactory = std::make_shared<BOF::BofBasicLoggerFactory>(true, ".");
std::shared_ptr<BOF::BofBasicLoggerFactory> psLoggerFactory = std::make_shared<BOF::BofBasicLoggerFactory>(true,false,false, ".");
MyLibInit(psLoggerFactory);
EXPECT_TRUE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_INIT] != nullptr);
EXPECT_TRUE(S_psLoggerCollection[UT_LOGGER_CHANNEL::UT_LOGGER_CHANNEL_CODEC] != nullptr);
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.0.3",
"version": "5.7.1.4",
"description": "The onbings general purpose C++ Multiplatform library",
"dependencies": [
{
Expand Down

0 comments on commit e571fbb

Please sign in to comment.