Allow to log messages to file on android

This commit is contained in:
Deve 2016-12-06 23:13:10 +01:00
parent 23883b83c1
commit c013fcea61

View File

@ -140,11 +140,11 @@ void Log::printMessage(int level, const char *component, const char *format,
android_LogPriority alp; android_LogPriority alp;
switch (level) switch (level)
{ {
// STK is using the levels slightly different from android // STK is using the levels slightly different from android
// (debug lowest, verbose above it; while android reverses // (debug lowest, verbose above it; while android reverses
// this order. So to get the same behaviour (e.g. filter // this order. So to get the same behaviour (e.g. filter
// out debug message, but still get verbose, we swap // out debug message, but still get verbose, we swap
// the order here. // the order here.
case LL_VERBOSE: alp = ANDROID_LOG_DEBUG; break; case LL_VERBOSE: alp = ANDROID_LOG_DEBUG; break;
case LL_DEBUG: alp = ANDROID_LOG_VERBOSE; break; case LL_DEBUG: alp = ANDROID_LOG_VERBOSE; break;
case LL_INFO: alp = ANDROID_LOG_INFO; break; case LL_INFO: alp = ANDROID_LOG_INFO; break;
@ -153,8 +153,8 @@ void Log::printMessage(int level, const char *component, const char *format,
case LL_FATAL: alp = ANDROID_LOG_FATAL; break; case LL_FATAL: alp = ANDROID_LOG_FATAL; break;
default: alp = ANDROID_LOG_FATAL; default: alp = ANDROID_LOG_FATAL;
} }
__android_log_vprint(alp, "SuperTuxKart", format, args); #endif
#else
static const char *names[] = {"debug", "verbose ", "info ", static const char *names[] = {"debug", "verbose ", "info ",
"warn ", "error ", "fatal "}; "warn ", "error ", "fatal "};
@ -178,8 +178,12 @@ void Log::printMessage(int level, const char *component, const char *format,
va_copy(out, args); va_copy(out, args);
setTerminalColor((LogLevel)level); setTerminalColor((LogLevel)level);
#ifdef ANDROID
__android_log_vprint(alp, "SuperTuxKart", format, out);
#else
printf("[%s] %s: ", names[level], component); printf("[%s] %s: ", names[level], component);
vprintf(format, out); vprintf(format, out);
#endif
resetTerminalColor(); // this prints a \n resetTerminalColor(); // this prints a \n
va_end(out); va_end(out);
@ -225,8 +229,6 @@ void Log::printMessage(int level, const char *component, const char *format,
MessageBoxA(NULL, message.c_str(), "SuperTuxKart - Fatal error", MB_OK); MessageBoxA(NULL, message.c_str(), "SuperTuxKart - Fatal error", MB_OK);
} }
#endif #endif
#endif
} // printMessage } // printMessage