From 0fad0feb49d56795b1f35c9a9827a648e7f205a8 Mon Sep 17 00:00:00 2001 From: Maxime ROUFFET Date: Sun, 11 Feb 2024 08:25:41 +0900 Subject: [PATCH] [Add] FrameNum --- Include/SA/Logger/Exceptions/Exception.hpp | 3 +++ Include/SA/Logger/Log/Log.hpp | 5 +++++ Include/SA/Logger/Logger.hpp | 9 +++++++++ Include/SA/Logger/Preprocessors/AssertMacro.hpp | 3 ++- Include/SA/Logger/Preprocessors/LogMacro.hpp | 6 ++++++ Source/SA/Logger/Exceptions/Exception.cpp | 3 ++- Source/SA/Logger/Log/Log.cpp | 7 ++++++- Source/SA/Logger/Logger.cpp | 14 ++++++++++++++ Tests/Prototype/main.cpp | 6 +++++- 9 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Include/SA/Logger/Exceptions/Exception.hpp b/Include/SA/Logger/Exceptions/Exception.hpp index ca84308..011a774 100644 --- a/Include/SA/Logger/Exceptions/Exception.hpp +++ b/Include/SA/Logger/Exceptions/Exception.hpp @@ -40,6 +40,9 @@ namespace SA /// Additional details string. std::wstring details; + + /// Frame num. + uint32_t frameNum; }; /** diff --git a/Include/SA/Logger/Log/Log.hpp b/Include/SA/Logger/Log/Log.hpp index fcd9734..7a5167b 100644 --- a/Include/SA/Logger/Log/Log.hpp +++ b/Include/SA/Logger/Log/Log.hpp @@ -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; @@ -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( @@ -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; }; diff --git a/Include/SA/Logger/Logger.hpp b/Include/SA/Logger/Logger.hpp index 6ebdbde..c1ee9d3 100644 --- a/Include/SA/Logger/Logger.hpp +++ b/Include/SA/Logger/Logger.hpp @@ -32,6 +32,8 @@ namespace SA protected: std::list mStreams; + uint32_t mFrameNum = 0u; + //{ Streams /** @@ -124,6 +126,13 @@ namespace SA */ virtual void Flush(); +//} + +//{ Frame Num + + void IncrementFrameNum(); + + uint32_t GetFrameNum() const; //} }; diff --git a/Include/SA/Logger/Preprocessors/AssertMacro.hpp b/Include/SA/Logger/Preprocessors/AssertMacro.hpp index f005e8f..89894f2 100644 --- a/Include/SA/Logger/Preprocessors/AssertMacro.hpp +++ b/Include/SA/Logger/Preprocessors/AssertMacro.hpp @@ -33,7 +33,8 @@ namespace SA __LINE__,\ __SA_FUNC_NAME,\ __SA_CHAN_NAME(_chan),\ - _dets\ + _dets,\ + __SA_LOG_FRAME_NUM\ }),\ ##__VA_ARGS__\ ) diff --git a/Include/SA/Logger/Preprocessors/LogMacro.hpp b/Include/SA/Logger/Preprocessors/LogMacro.hpp index 11e7ed7..1a07259 100644 --- a/Include/SA/Logger/Preprocessors/LogMacro.hpp +++ b/Include/SA/Logger/Preprocessors/LogMacro.hpp @@ -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 //} @@ -67,6 +70,7 @@ namespace SA SA::LogLevel::_lvl,\ __SA_CHAN_NAME(_chan),\ SA::StringFormat(__SA_UNPARENT(_dets)),\ + __SA_LOG_FRAME_NUM,\ std::string()\ ) @@ -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__) } diff --git a/Source/SA/Logger/Exceptions/Exception.cpp b/Source/SA/Logger/Exceptions/Exception.cpp index 1189c6b..33ceb4d 100644 --- a/Source/SA/Logger/Exceptions/Exception.cpp +++ b/Source/SA/Logger/Exceptions/Exception.cpp @@ -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) { } } diff --git a/Source/SA/Logger/Log/Log.cpp b/Source/SA/Logger/Log/Log.cpp index 46b0b22..8369de8 100644 --- a/Source/SA/Logger/Log/Log.cpp +++ b/Source/SA/Logger/Log/Log.cpp @@ -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) }, @@ -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() } { @@ -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'}'; diff --git a/Source/SA/Logger/Logger.cpp b/Source/SA/Logger/Logger.cpp index 9ef4de5..2b8b7e1 100644 --- a/Source/SA/Logger/Logger.cpp +++ b/Source/SA/Logger/Logger.cpp @@ -60,5 +60,19 @@ namespace SA (*it)->Flush(); } +//} + +//{ Frame Num + + void Logger::IncrementFrameNum() + { + mFrameNum = (mFrameNum + 1) % 1000; + } + + uint32_t Logger::GetFrameNum() const + { + return mFrameNum; + } + //} } diff --git a/Tests/Prototype/main.cpp b/Tests/Prototype/main.cpp index d58a4f6..d112e0d 100644 --- a/Tests/Prototype/main.cpp +++ b/Tests/Prototype/main.cpp @@ -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);