Skip to content

Commit

Permalink
[Add] FrameNum
Browse files Browse the repository at this point in the history
  • Loading branch information
mrouffet committed Feb 10, 2024
1 parent 18d2242 commit 0fad0fe
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Include/SA/Logger/Exceptions/Exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ namespace SA

/// Additional details string.
std::wstring details;

/// Frame num.
uint32_t frameNum;
};

/**
Expand Down
5 changes: 5 additions & 0 deletions Include/SA/Logger/Log/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace SA
/// Additional details string.
std::wstring details;

/// Frame number.
uint32_t frameNum = 0u;

/// backtracing of logging call.
std::string backtrace;

Expand All @@ -61,6 +64,7 @@ namespace SA
* \param[in] _level Level of the Log.
* \param[in] _chanName Channel's name of the Log.
* \param[in] _details Additional details to display.
* \param[in] _frameNum Frame number of the Log.
* \param[in] _backtrace backtracing of logging call.
*/
Log(
Expand All @@ -71,6 +75,7 @@ namespace SA
LogLevel _level = LogLevel::Normal,
std::wstring _chanName = L"Default",
std::wstring _details = L"",
uint32_t _frameNum = 0u,
std::string _backtrace = ""
) noexcept;
};
Expand Down
9 changes: 9 additions & 0 deletions Include/SA/Logger/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace SA
protected:
std::list<ALogStream*> mStreams;

uint32_t mFrameNum = 0u;

//{ Streams

/**
Expand Down Expand Up @@ -124,6 +126,13 @@ namespace SA
*/
virtual void Flush();

//}

//{ Frame Num

void IncrementFrameNum();

uint32_t GetFrameNum() const;
//}
};

Expand Down
3 changes: 2 additions & 1 deletion Include/SA/Logger/Preprocessors/AssertMacro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace SA
__LINE__,\
__SA_FUNC_NAME,\
__SA_CHAN_NAME(_chan),\
_dets\
_dets,\
__SA_LOG_FRAME_NUM\
}),\
##__VA_ARGS__\
)
Expand Down
6 changes: 6 additions & 0 deletions Include/SA/Logger/Preprocessors/LogMacro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ namespace SA
else\
std::cerr << "Try logging with invalid logger instance or callback! Initialize SA::Debug::logger or SA::Debug::logCB." << std::endl;

#define __SA_LOG_FRAME_NUM\
SA::Debug::logger ? SA::Debug::logger->GetFrameNum() : 0u

/// \endcond

//}
Expand All @@ -67,6 +70,7 @@ namespace SA
SA::LogLevel::_lvl,\
__SA_CHAN_NAME(_chan),\
SA::StringFormat(__SA_UNPARENT(_dets)),\
__SA_LOG_FRAME_NUM,\
std::string()\
)

Expand Down Expand Up @@ -131,6 +135,8 @@ namespace SA

#elif SA_DEBUG || SA_LOG_RELEASE_OPT

#define SA_LOG_END_OF_FRAME() { if(SA::Debug::logger) SA::Debug::logger->IncrementFrameNum(); }

#define SA_LOG(...) { __SA_SELECT_LOG_MACRO(__VA_ARGS__, __SA_LOG5, __SA_LOG4, __SA_LOG3, __SA_LOG2, __SA_LOG1)(__VA_ARGS__) }

#define SA_WARN(_pred, ...) { __SA_COND_LOG(_pred, Warning, ##__VA_ARGS__) }
Expand Down
3 changes: 2 additions & 1 deletion Source/SA/Logger/Exceptions/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace SA
std::move(_msg),
_pred ? LogLevel::AssertSuccess : LogLevel::AssertFailure,
std::move(_info.chanName),
std::move(_info.details))
std::move(_info.details),
_info.frameNum)
{
}
}
7 changes: 6 additions & 1 deletion Source/SA/Logger/Log/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace SA
LogLevel _level,
std::wstring _chanName,
std::wstring _details,
uint32_t _frameNum,
std::string _backtrace
) noexcept :
file{ std::move(_file) },
Expand All @@ -21,6 +22,7 @@ namespace SA
level{_level },
chanName{ std::move(_chanName) },
details{ std::move(_details) },
frameNum{ _frameNum },
backtrace{ std::move(_backtrace) },
date{ DateTime::Now() }
{
Expand All @@ -33,7 +35,10 @@ namespace SA
// Output date.
str += L'[' + SA::ToWString(_log.date.hour) +
L':' + SA::ToWString(_log.date.minute) +
L':' + SA::ToWString(_log.date.second) + L"] ";
L':' + SA::ToWString(_log.date.second) + L']';

// Output FrameNum.
str += L'[' + SA::ToWString(_log.frameNum) + L"] ";

// Output level and channel.
str += L'{' + SA::ToWString(_log.level) + L" - " + _log.chanName + L'}';
Expand Down
14 changes: 14 additions & 0 deletions Source/SA/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,19 @@ namespace SA
(*it)->Flush();
}

//}

//{ Frame Num

void Logger::IncrementFrameNum()
{
mFrameNum = (mFrameNum + 1) % 1000;
}

uint32_t Logger::GetFrameNum() const
{
return mFrameNum;
}

//}
}
6 changes: 5 additions & 1 deletion Tests/Prototype/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ int main()

//{ Test Data Race

for(int i = 0; i < 10; ++i)
for (int i = 0; i < 10; ++i)
{
SA_LOG("Hello, World!", Info, SA/TestChan, "Some Details!");

SA_LOG_END_OF_FRAME();
}

try
{
SA_ASSERT((OutOfRange, 4u, 1u, 3u), SA/OtherChan);
Expand Down

0 comments on commit 0fad0fe

Please sign in to comment.