Added redirection of ConsoleAppender to logcat, if used on android.

Using custom default format for log messages on android.
This commit is contained in:
Armin Novak 2014-08-07 17:47:59 +02:00
parent 219a760bad
commit 1a37435a26
2 changed files with 45 additions and 1 deletions

View File

@ -30,6 +30,10 @@
#include "wlog/ConsoleAppender.h"
#ifdef ANDROID
#include <android/log.h>
#endif
/**
* Console Appender
*/
@ -84,11 +88,45 @@ int WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender,
return 1;
}
#endif
#ifdef ANDROID
(void)fp;
android_LogPriority level;
switch(log->Level)
{
case WLOG_TRACE:
level = ANDROID_LOG_VERBOSE;
break;
case WLOG_DEBUG:
level = ANDROID_LOG_DEBUG;
break;
case WLOG_INFO:
level = ANDROID_LOG_INFO;
break;
case WLOG_WARN:
level = ANDROID_LOG_WARN;
break;
case WLOG_ERROR:
level = ANDROID_LOG_ERROR;
break;
case WLOG_FATAL:
level = ANDROID_LOG_FATAL;
break;
case WLOG_OFF:
level = ANDROID_LOG_SILENT;
break;
default:
level = ANDROID_LOG_FATAL;
break;
}
if (level != ANDROID_LOG_SILENT)
__android_log_print(level, "winpr", "%s%s", message->PrefixString, message->TextString);
#else
fp = (appender->outputStream == WLOG_CONSOLE_STDERR) ? stderr : stdout;
fprintf(fp, "%s%s\n", message->PrefixString, message->TextString);
#endif
return 1;
}

View File

@ -356,7 +356,13 @@ wLogLayout* WLog_Layout_New(wLog* log)
if (env)
layout->FormatString = env;
else
{
#ifdef ANDROID
layout->FormatString = _strdup("[%mn][pid=%pid:tid=%tid]");
#else
layout->FormatString = _strdup("[%hr:%mi:%se:%ml] [%pid:%tid] [%lv][%mn] - ");
#endif
}
}
return layout;