28 #include "BasicPlatformDebug.h" 29 #include "FormatMessage.h" 30 #include "BasicFileSystem.h" 33 void ThrowIf(std::string &&)
38 inline void ThrowIf<true>(std::string &&msg)
40 throw std::runtime_error( std::move(msg) );
43 template<
bool bThrowException,
typename FirstArgType,
typename... RestArgsType>
44 void LogError(
const char *strFunctionName,
const char *strFullFilePath,
int Line,
const FirstArgType& first,
const RestArgsType&... RestArgs )
47 BasicFileSystem::SplitFilePath( strFullFilePath,
nullptr, &FileName );
48 Diligent::MsgStream ss;
49 ss <<
"The following error occured in the " << strFunctionName <<
"() function (" << FileName <<
", line " << Line <<
"):\n";
50 Diligent::FormatMsg( ss, first, RestArgs... );
51 auto strFullMessage = ss.str();
52 OutputDebugMessage( bThrowException ? BasicPlatformDebug::DebugMessageSeverity::FatalError : BasicPlatformDebug::DebugMessageSeverity::Error, strFullMessage.c_str() );
53 ThrowIf<bThrowException>(std::move(strFullMessage));
56 #define LOG_ERROR(...)\ 58 LogError<false>(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ 61 #define LOG_ERROR_ONCE(...)\ 63 static bool IsFirstTime = true; \ 66 LogError<false>(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ 67 IsFirstTime = false; \ 71 #define LOG_ERROR_AND_THROW(...)\ 73 LogError<true>(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__);\ 76 #define LOG_DEBUG_MESSAGE(Severity, ...)\ 78 Diligent::MsgStream ss; \ 79 Diligent::FormatMsg( ss, ##__VA_ARGS__ );\ 80 OutputDebugMessage( Severity, ss.str().c_str() );\ 83 #define LOG_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(BasicPlatformDebug::DebugMessageSeverity::Error, ##__VA_ARGS__) 84 #define LOG_WARNING_MESSAGE(...) LOG_DEBUG_MESSAGE(BasicPlatformDebug::DebugMessageSeverity::Warning, ##__VA_ARGS__) 85 #define LOG_INFO_MESSAGE(...) LOG_DEBUG_MESSAGE(BasicPlatformDebug::DebugMessageSeverity::Info, ##__VA_ARGS__) 87 #define LOG_DEBUG_MESSAGE_ONCE(Severity, ...)\ 89 static bool IsFirstTime = true; \ 92 LOG_DEBUG_MESSAGE(Severity, ##__VA_ARGS__);\ 93 IsFirstTime = false; \ 97 #define LOG_ERROR_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(BasicPlatformDebug::DebugMessageSeverity::Error, ##__VA_ARGS__) 98 #define LOG_WARNING_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(BasicPlatformDebug::DebugMessageSeverity::Warning, ##__VA_ARGS__) 99 #define LOG_INFO_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(BasicPlatformDebug::DebugMessageSeverity::Info, ##__VA_ARGS__)