1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #pragma once19 20 #include "[Math/MathNamespace.h]"21 22 #include <stdio.h>23 24 #if defined(ANDROID)25 26 #include <android/log.h>27 #endif28 29 #ifdef WIN8PHONE30 #ifndef NOMINMAX31 #define NOMINMAX32 #endif33 #include <Windows.h>34 #endif35 36 [MATH_BEGIN_NAMESPACE]37 38 39 #ifdef _MSC_VER40 #define MULTI_LINE_MACRO_BEGIN do { \41 __pragma(warning(push)) \42 __pragma(warning(disable:4127))43 44 #define MULTI_LINE_MACRO_END \45 } while(0) \46 __pragma(warning(pop))47 48 #else49 50 #define MULTI_LINE_MACRO_BEGIN do {51 #define MULTI_LINE_MACRO_END } while(0)52 53 #endif54 55 56 typedef unsigned int [LogChannel];57 58 namespace59 {60 const [LogChannel] LogUser = 1; 61 const [LogChannel] LogInfo = 2; 62 const [LogChannel] LogError = 4; 63 const [LogChannel] LogWarning = 8; 64 const [LogChannel] LogObjectAlloc = 16; 65 const [LogChannel] LogData = 32; 66 const [LogChannel] LogVerbose = 64; 67 const [LogChannel] LogWaits = 128; 68 }69 70 71 72 73 74 75 76 void [TimeOutputDebugStringVariadic]([LogChannel] logChannel, const char *filename, int lineNumber, const char *msg, ...);77 78 79 void [TimeOutputDebugString]([LogChannel] logChannel, const char *filename, int lineNumber, const char *msg);80 81 82 83 void [SetLogChannels]([LogChannel] logChannel);84 85 86 [LogChannel] [GetLogChannels]();87 88 89 90 91 92 93 94 void [SetLogFile](const char *filename);95 96 97 98 void [EnableMemoryLeakLoggingAtExit]();99 100 enum [ConsoleTextColor]101 {102 ColorRed = 4, 103 [ColorGreen] = 2, 104 [ColorBlue] = 1, 105 [ColorIntensity] = 8 106 };107 108 109 void [SetStdoutTextColor](int newColor);110 111 112 #define LOGUSER(msg, ...) ( (TimeOutputDebugStringVariadic(LogUser, __FILE__, __LINE__, msg, ##__VA_ARGS__), true) )113 114 #define STRINGIZE_HELPER(x) #x115 #define STRINGIZE(x) STRINGIZE_HELPER(x)116 #define WARNING(desc) message(__FILE__ "(" STRINGIZE(__LINE__) ") : warning: " #desc)117 118 #if defined(NPAPI) && !defined(LOGGING_SUPPORT_DISABLED)119 120 void logmsg(const char *msg);121 122 #define LOGI(...) \123 MULTI_LINE_MACRO_BEGIN \124 char str____[16384]; \125 sprintf(str____, __VA_ARGS__); \126 logmsg(str____); \127 logmsg("\n"); \128 MULTI_LINE_MACRO_END129 130 #define LOGW(...) \131 MULTI_LINE_MACRO_BEGIN \132 char str____[16384]; \133 logmsg("Warning: "); \134 sprintf(str____, __VA_ARGS__); \135 logmsg(str____); \136 logmsg("\n"); \137 MULTI_LINE_MACRO_END138 139 #define LOGE(...) \140 MULTI_LINE_MACRO_BEGIN \141 char str____[16384]; \142 logmsg("Error: "); \143 sprintf(str____, __VA_ARGS__); \144 logmsg(str____); \145 logmsg("\n"); \146 MULTI_LINE_MACRO_END147 148 #define LOG(channel, ...) \149 MULTI_LINE_MACRO_BEGIN \150 \151 { \152 char str____[16384]; \153 logmsg(#channel); \154 sprintf(str____, __VA_ARGS__); \155 logmsg(str____); \156 logmsg("\n"); \157 } \158 MULTI_LINE_MACRO_END159 160 #elif defined(ANDROID) && !defined(LOGGING_SUPPORT_DISABLED)161 162 #ifndef LOG163 #define LOG(channel, ...) do { (void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__); } while(0)164 #endif165 #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "native-activity", __VA_ARGS__))166 #define LOGW(...) do { \167 char logfunc_str[512]; \168 sprintf(logfunc_str, __VA_ARGS__); \169 char logfunc_str2[512]; \170 sprintf(logfunc_str2, "Warning: %s", logfunc_str); \171 ((void)__android_log_print(ANDROID_LOG_WARN, "native-activity", logfunc_str2)); \172 } while(0)173 174 #define LOGE(...) do { \175 char logfunc_str[512]; \176 sprintf(logfunc_str, __VA_ARGS__); \177 char logfunc_str2[512]; \178 sprintf(logfunc_str2, "Error: %s", logfunc_str); \179 ((void)__android_log_print(ANDROID_LOG_ERROR, "native-activity", logfunc_str2)); \180 } while(0)181 182 #elif defined(WIN8PHONE) && !defined(LOGGING_SUPPORT_DISABLED)183 184 #define LOGI(...) \185 MULTI_LINE_MACRO_BEGIN \186 char str____[16384]; \187 sprintf(str____, __VA_ARGS__); \188 OutputDebugStringA(str____); \189 OutputDebugStringA("\r\n"); \190 MULTI_LINE_MACRO_END191 192 #define LOGW(...) \193 MULTI_LINE_MACRO_BEGIN \194 char str____[16384]; \195 OutputDebugStringA("Warning: "); \196 sprintf(str____, __VA_ARGS__); \197 OutputDebugStringA(str____); \198 OutputDebugStringA("\r\n"); \199 MULTI_LINE_MACRO_END200 201 #define LOGE(...) \202 MULTI_LINE_MACRO_BEGIN \203 char str____[16384]; \204 OutputDebugStringA("Error: "); \205 sprintf(str____, __VA_ARGS__); \206 OutputDebugStringA(str____); \207 OutputDebugStringA("\r\n"); \208 MULTI_LINE_MACRO_END209 210 #define LOG(channel, ...) \211 MULTI_LINE_MACRO_BEGIN \212 \213 { \214 char str____[16384]; \215 OutputDebugStringA(#channel); \216 sprintf(str____, __VA_ARGS__); \217 OutputDebugStringA(str____); \218 OutputDebugStringA("\r\n"); \219 } \220 MULTI_LINE_MACRO_END221 222 #elif defined(WIN32) && !defined(LOGGING_SUPPORT_DISABLED)223 224 #ifndef LOG225 #define LOG(channel, ...) \226 MULTI_LINE_MACRO_BEGIN \227 printf(__VA_ARGS__); \228 printf("\n"); \229 MULTI_LINE_MACRO_END230 #endif231 232 #define LOGI(...) \233 MULTI_LINE_MACRO_BEGIN \234 printf(__VA_ARGS__); \235 printf("\n"); \236 MULTI_LINE_MACRO_END237 238 #define LOGW(...) \239 MULTI_LINE_MACRO_BEGIN \240 SetStdoutTextColor(ColorRed | ColorGreen | ColorIntensity); \241 printf("Warning: "); printf(__VA_ARGS__); printf("\n"); \242 SetStdoutTextColor(ColorRed | ColorGreen | ColorBlue); \243 MULTI_LINE_MACRO_END244 245 #define LOGE(...) \246 MULTI_LINE_MACRO_BEGIN \247 SetStdoutTextColor(ColorRed | ColorIntensity); \248 printf("Error: "); printf(__VA_ARGS__); printf("\n"); \249 SetStdoutTextColor(ColorRed | ColorGreen | ColorBlue); \250 MULTI_LINE_MACRO_END251 252 #elif (defined(PEPPER) || defined(__APPLE__) || defined(__GNUC__) || defined(EMSCRIPTEN) || defined(__FLASHPLAYER__)) && !defined(LOGGING_SUPPORT_DISABLED)253 254 255 256 #define LOG(channel, ...) do { printf(__VA_ARGS__); printf("\n"); } while(0)257 #define LOGI(...) do { printf(__VA_ARGS__); printf("\n"); } while(0)258 #define LOGW(...) do { printf("Warning: "); printf(__VA_ARGS__); printf("\n"); } while(0)259 #define LOGE(...) do { printf("Error: "); printf(__VA_ARGS__); printf("\n"); } while(0)260 261 262 263 264 265 266 #elif defined(LOGGING_SUPPORT_DISABLED)267 268 269 270 #define LOG(...) ((void)0)271 #define LOGE(...) ((void)0)272 #define LOGW(...) ((void)0)273 #define LOGI(...) ((void)0)274 275 #else276 277 #error LOG/LOGE/LOGW/LOGI not implemented!278 #endif279 280 #ifdef GFXAPI_TRACE_ENABLED281 #define TRACE LOGI282 #else283 #define TRACE(...) ((void)0)284 #endif285 286 [MATH_END_NAMESPACE] Go back to previous page