From d8dfbbe2d2bf2f8eee8eb927b6f6a8fdccbbab2a Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 24 Jan 2022 05:44:43 +0300 Subject: [PATCH] [android] Use android logger (#585) --- libtransmission/log.cc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libtransmission/log.cc b/libtransmission/log.cc index cb96f1577..4e43717f8 100644 --- a/libtransmission/log.cc +++ b/libtransmission/log.cc @@ -16,8 +16,13 @@ #include "tr-assert.h" #include "utils.h" +#ifdef __ANDROID__ +#include +#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; }