[android] Use android logger (#585)

This commit is contained in:
Andrey 2022-01-24 05:44:43 +03:00 committed by GitHub
parent b5cbbb7f8f
commit d8dfbbe2d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 deletions

View File

@ -16,8 +16,13 @@
#include "tr-assert.h"
#include "utils.h"
#ifdef __ANDROID__
#include <android/log.h>
#endif
using namespace std::literals;
tr_log_level __tr_message_level = TR_LOG_ERROR;
static bool myQueueEnabled = false;
@ -228,8 +233,32 @@ void tr_logAddMessage(char const* file, int line, tr_log_level level, char const
OutputDebugStringA(buf);
}
#elif defined(__ANDROID__)
int prio;
switch (level) {
case TR_LOG_ERROR:
prio = ANDROID_LOG_ERROR;
break;
case TR_LOG_INFO:
prio = ANDROID_LOG_INFO;
break;
case TR_LOG_DEBUG:
prio = ANDROID_LOG_DEBUG;
break;
default:
prio = ANDROID_LOG_VERBOSE;
}
#ifdef NDEBUG
__android_log_print(prio, "transmission", "%s", buf);
#else
__android_log_print(prio, "transmission", "[%s:%d] %s", file, line, buf);
#endif
#else
if (!tr_str_is_empty(buf))
{
if (tr_logGetQueueEnabled())
@ -275,6 +304,7 @@ void tr_logAddMessage(char const* file, int line, tr_log_level level, char const
tr_sys_file_flush(fp, nullptr);
}
}
#endif
errno = err;
}