1 #ifndef LOGGER_H_ 2 #define LOGGER_H_ 3 4 #include <SDL2/SDL.h> 5 #include <string> 6 #include <memory.h> 7 8 namespace Logger 9 { 10 void GetOutputString(std::string& outOutputBuffer, const std::string& tag, const std::string& message, const char* funcName, const char* sourceFile, unsigned int lineNum); 11 } 12 13 14 // Errors are bad and potentially fatal. They are presented as a dialog with Abort, Retry, and Ignore. Abort will 15 // break into the debugger, retry will continue the game, and ignore will continue the game and ignore every subsequent 16 // call to this specific error. They are ignored completely in release mode. 17 #define LOG_ERROR(str) \ 18 do \ 19 { \ 20 std::string s((str)); \ 21 std::string out; \ 22 Logger::GetOutputString(out, "", s, __FUNCTION__, NULL, __LINE__); \ 23 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", out.c_str()); \ 24 } \ 25 while (0); \ 26 27 #define LOG_ASSERT(str) \ 28 do \ 29 { \ 30 std::string s((str)); \ 31 std::string out; \ 32 Logger::GetOutputString(out, "", s, __FUNCTION__, NULL, __LINE__); \ 33 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s", out.c_str()); \ 34 assert(false); \ 35 } \ 36 while (0); \ 37 38 // Warnings are recoverable. They are just logs with the "WARNING" tag that displays calling information. The flags 39 // are initially set to WARNINGFLAG_DEFAULT (defined in debugger.cpp), but they can be overridden normally. 40 #define LOG_WARNING(str) \ 41 do \ 42 { \ 43 std::string s((str)); \ 44 std::string out; \ 45 Logger::GetOutputString(out, std::string(""), s, __FUNCTION__, NULL, __LINE__); \ 46 SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "%s", out.c_str()); \ 47 } \ 48 while (0);\ 49 50 #define LOG_TAG(tag, str) \ 51 do \ 52 { \ 53 std::string s((str)); \ 54 std::string out; \ 55 Logger::GetOutputString(out, tag, s, NULL, NULL, 0); \ 56 SDL_Log("%s", out.c_str()); \ 57 } \ 58 while (0);\ 59 60 #define LOG(str) \ 61 do \ 62 { \ 63 std::string s((str)); \ 64 std::string out; \ 65 Logger::GetOutputString(out, "", s, NULL, NULL, 0); \ 66 SDL_Log("%s", out.c_str()); \ 67 } \ 68 while (0);\ 69 70 #define LOG_TRACE(str) \ 71 do \ 72 { \ 73 std::string s((str)); \ 74 std::string out; \ 75 Logger::GetOutputString(out, "", s, __FUNCTION__, NULL, __LINE__); \ 76 SDL_Log("%s", out.c_str()); \ 77 } \ 78 while (0); \ 79 80 #endif