diff options
author | Max Kellermann <max@duempel.org> | 2014-02-21 22:52:19 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-22 00:18:46 +0100 |
commit | 90114514a9d9439f7ed9519f2956bb00942771c5 (patch) | |
tree | a20e96f56ceb07c6426c147df40ec04b988d69c8 /src/LogBackend.cxx | |
parent | 7757e59e7874ed160702483bbbd62c518e8195eb (diff) | |
download | mpd-90114514a9d9439f7ed9519f2956bb00942771c5.tar.gz mpd-90114514a9d9439f7ed9519f2956bb00942771c5.tar.xz mpd-90114514a9d9439f7ed9519f2956bb00942771c5.zip |
LogBackend: use __android_log_print() on Android
Diffstat (limited to 'src/LogBackend.cxx')
-rw-r--r-- | src/LogBackend.cxx | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/LogBackend.cxx b/src/LogBackend.cxx index ba37c1dbb..3cd907179 100644 --- a/src/LogBackend.cxx +++ b/src/LogBackend.cxx @@ -36,6 +36,33 @@ #include <syslog.h> #endif +#ifdef ANDROID +#include <android/log.h> + +static int +ToAndroidLogLevel(LogLevel log_level) +{ + switch (log_level) { + case LogLevel::DEBUG: + return ANDROID_LOG_DEBUG; + + case LogLevel::INFO: + case LogLevel::DEFAULT: + return ANDROID_LOG_INFO; + + case LogLevel::WARNING: + return ANDROID_LOG_WARN; + + case LogLevel::ERROR: + return ANDROID_LOG_ERROR; + } + + assert(false); + gcc_unreachable(); +} + +#else + static LogLevel log_threshold = LogLevel::INFO; #ifdef HAVE_GLIB @@ -176,9 +203,16 @@ FileLog(const Domain &domain, const char *message) #endif } +#endif /* !ANDROID */ + void Log(const Domain &domain, LogLevel level, const char *msg) { +#ifdef ANDROID + __android_log_print(ToAndroidLogLevel(level), "MPD", + "%s: %s", domain.GetName(), msg); +#else + if (level < log_threshold) return; @@ -190,4 +224,5 @@ Log(const Domain &domain, LogLevel level, const char *msg) #endif FileLog(domain, msg); +#endif /* !ANDROID */ } |